简体   繁体   English

ActiveRecord :: StatementInvalid:PG :: UndefinedColumn:错误

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

相关问题 ActiveRecord::StatementInvalid PG::UndefinedColumn: 错误 - ActiveRecord::StatementInvalid PG::UndefinedColumn: ERROR ActiveRecord :: StatementInvalid:Rails中的PG :: UndefinedColumn - ActiveRecord::StatementInvalid: PG::UndefinedColumn in Rails Rails/Grape 应用程序中的排序错误 ActiveRecord::StatementInvalid PG::UndefinedColumn - Sorting error ActiveRecord::StatementInvalid PG::UndefinedColumn in Rails/Grape app ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column rooms.hotel 不存在 LINE 1: - ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column rooms.hotel does not exist LINE 1: ActiveRecord :: StatementInvalid:PG :: UndefinedColumn:错误:.having(&#39;order_count&gt; 5&#39;)时,列“ order_count”不存在 - ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column “order_count” does not exist when .having('order_count > 5') ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:在Rails查询中 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: in rails query Rails抛出ActiveRecord :: StatementInvalid PG :: NotNullViolation:错误 - Rails throwing ActiveRecord::StatementInvalid PG::NotNullViolation: ERROR ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:关系 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation ActiveRecord::StatementInvalid: PG InFailedSqlTransaction - ActiveRecord::StatementInvalid: PG InFailedSqlTransaction ActiveRecord :: StatementInvalid(PG :: UndefinedFunction - ActiveRecord::StatementInvalid (PG::UndefinedFunction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM