简体   繁体   English

Heroku - 不起作用“rake”命令:PG ::错误:错误:关系“roles”不存在

[英]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: 当我运行heroku run rake db:migrate ,我会收到此错误:

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. 我也尝试重置数据库: heroku run rake db:reset但是我得到了与上面相同的错误。 It looks like the command heroku rake doesn't work. 看起来命令heroku rake不起作用。 Also, I've tried to move my whole local database to Heorku - heroku db:push - and this is working. 此外,我试图将我的整个本地数据库移动到Heorku - heroku db:push - 这是有效的。 But I would need to run my migrations. 但我需要运行我的迁移。

This is a common error you will see when running Rolify and migrating. 这是运行Rolify和迁移时常见的错误。

You need to check your Rolify initializer file config/initializers/rolify.rb . 您需要检查Rolify初始化程序文件config/initializers/rolify.rb if the command config.use_dynamic_shortcuts is uncommented, then comment it. 如果取消注释config.use_dynamic_shortcuts命令,则对其进行注释。 Push up your changes and then run rake db:migrate . 推高您的更改,然后运行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. 问题是rails加载了初始化程序文件,如果尚未迁移数据库, use_dynamic_shortcuts将引发错误。

Have you made sure you committed everything? 你确定你承诺了一切吗? Try git status then git add . 尝试git status然后git add . then do a git push heroku again. 然后再做一个git push heroku

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: 如果您无法迁移,mybe您的迁移不正确,请尝试应用架构:

heroku rake db:schema:apply

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. 听起来你可能在初始化器(或类似的东西)中引用了一个引用Role类的代码 - 因为当环境旋转时表不存在(即使你试图设置表!)它会产生错误。

Try removing the code referencing the Role class, migrating the database, then putting the code back in. 尝试删除引用Role类的代码,迁移数据库,然后重新放入代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku迁移:PG ::错误:错误:关系“角色”不存在 - Heroku migration: PG::Error: ERROR: relation “roles” does not exist heroku rake migration db错误关系“ post”不存在 - heroku rake migrate db error relation “post” doesn't exist 耙子流产了! PG :: UndefinedTable:错误:关系“页面”不存在 - rake aborted! PG::UndefinedTable: ERROR: relation “pages” does not exist PG ::错误:错误:关系“用户”在Heroku上不存在 - PG::Error: ERROR: relation “users” does not exist on Heroku PG::UndefinedTable:错误:尝试运行时关系“user_profiles”不存在:heroku run rake db:migrate - PG::UndefinedTable: ERROR: relation "user_profiles" does not exist when trying to run : heroku run rake db:migrate 全球化,Heroku:PG :: UndefinedTable:错误:关系不存在 - Globalize, Heroku: PG::UndefinedTable: ERROR: relation does not exist PG:错误关系不存在 - PG:Error relation does not exist Travis CI“ rake db:migrate”或“ rake db:test:prepare”会导致rake中止! PG ::错误:错误:关系“设置”不存在 - Travis CI “rake db:migrate” or “rake db:test:prepare” causes rake aborted! PG::Error: ERROR: relation “settings” does not exist 我运行 heroku 运行 rake db:migrate 但我收到错误 PG::UndefinedColumn: ERROR: 关系“tasks”的列“user_id”不存在 - I run heroku run rake db:migrate but I got error PG::UndefinedColumn: ERROR: column “user_id” of relation “tasks” does not exist Rails联接表名称与迁移或架构不匹配(PG :: UndefinedTable:错误:关系不存在) - Rails join table name doesn't match migration or schema (PG::UndefinedTable: ERROR: relation does not exist)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM