[英]ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR
I'm getting an error when trying to run rake db:migrate
: 尝试运行
rake db:migrate
时出现错误:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "plus_ids" of relation "comments" does not exist
I guess I did do some funky stuff when trying to remove the attribute plus_ids from my comment model. 我想在尝试从评论模型中删除属性plus_ids时确实做了一些时髦的事情。 I'm not sure what is going on.
我不确定发生了什么。
If I do a rake db:reset
and then fetch the live database it all works locally again, but if I try to do a rake db:migrate
it throws an error again. 如果我执行
rake db:reset
然后获取实时数据库,则所有这些都将再次在本地工作,但是如果我尝试执行rake db:migrate
它将再次引发错误。
How can I get rid of plus_ids properly so I can migrate? 如何正确去除plus_ids以便迁移?
Edit 1: Here's the migration files when I added (and removed) the attribute: 编辑1:这是我添加(和删除)属性后的迁移文件:
class RemovePlusIdsFromComments < ActiveRecord::Migration
def change
remove_column :comments, :plus_ids, :integer
end
end
And then 接着
class AddPlusIdsToComments < ActiveRecord::Migration
def change
add_column :comments, :plus_ids, :integer
end
end
They're in the wrong order in the migration list, not sure why. 它们在迁移列表中的顺序错误,不确定原因。
Edit 2: I think there is something wrong with the Up/Down, if I run rake db:migrate:status
I get this: 编辑2:我认为上/下有问题,如果我运行
rake db:migrate:status
我会得到:
down 20150305203336 Remove plus ids from comments
down 20150305204404 Add plus ids to comments
Any way around this? 可以解决吗?
The answer was to run 答案是跑
rake db:migrate:up VERSION=20150305204404
On both live and local, and then 在现场和本地,然后
rake db:migrate
On both again. 再次上。 Now the live and local database is in sync again, and migrating the database throws no errors.
现在,实时数据库和本地数据库再次同步,并且迁移数据库不会引发任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.