[英]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.