user984621
user984621

Reputation: 48453

Heroku - doesn't work "rake" command: PG::Error: ERROR: relation "roles" does not exist

When I run heroku run rake db:migrate, I'll get this error:

rake aborted!
PG::Error: ERROR:  relation "roles" does not exist
LINE 4:              WHERE a.attrelid = '"roles"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"roles"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

Tasks: TOP => db:reset => environment

I've also tried to reset the database: heroku run rake db:reset but I've got the same error as above. It looks like the command heroku rake doesn't work. Also, I've tried to move my whole local database to Heorku - heroku db:push - and this is working. But I would need to run my migrations.

Upvotes: 1

Views: 1368

Answers (4)

jameswilliamiii
jameswilliamiii

Reputation: 878

This is a common error you will see when running Rolify and migrating.

You need to check your Rolify initializer file config/initializers/rolify.rb. if the command config.use_dynamic_shortcuts is uncommented, then comment it. Push up your changes and then run rake db:migrate. After you successfully migrate, then you can go back and uncomment the line.

The problem is that rails loads the initializer files and use_dynamic_shortcuts will throw an error if the database has not been migrated yet.

Upvotes: 3

sevenseacat
sevenseacat

Reputation: 25029

It sounds like you may have code in an initializer (or something similar) that is referencing a Role class - because the table doesn't exist when the environment is spun up (even if you're trying to set up the table!) it will generate an error.

Try removing the code referencing the Role class, migrating the database, then putting the code back in.

Upvotes: 0

rewritten
rewritten

Reputation: 16435

Try to run

heroku pg:reset

It will try to reset your database to a sane state. Then you can migrate and seed.

If you can't migrate, mybe your migrations are not correct, try to apply the schema:

heroku rake db:schema:apply

Upvotes: 0

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

Have you made sure you committed everything? Try git status then git add . then do a git push heroku again.

Upvotes: 0

Related Questions