0

我创建了一个迁移来更改我的数据模型,以使我的对话模型具有多态性。

这是我的文件,精简:

# deal.rb
class Deal < ActiveRecord::Base
  has_many :conversations, as: :conversationable
end

# conversation.rb
class Conversation < ActiveRecord::Base
    belongs_to :conversationable, polymorphic: true
end

在我的seeds.rb 中,我正在调用该行:

conversation = deal.conversations.create!(:seller_id => deal.user.id, :buyer_id => user.id)

这会产生错误:

SQLite3::SQLException: table conversations has no column named deal_id: INSERT INTO "conversations" ("buyer_id", "conversationable_id", "conversationable_type", "created_at", "deal_id", "seller_id", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)

为什么rails仍在插入deal_id?我必须删除其他地方的关联残余吗?

在 rails 控制台中运行相同的代码时,会创建具有正确关联的模型。

谢谢你。

4

1 回答 1

0

想通了(感谢 Ryan Biggs)。

问题是要重置我的应用程序,我在打电话

rake db:drop && rake db:migrate && rake db:seed

这没有为在迁移和播种之间重新加载列信息提供足够的时间。

于 2013-09-10T01:44:43.537 回答