Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails多态关联正在插入一个额外字段_Ruby On Rails_Polymorphic Associations - Fatal编程技术网

Ruby on rails Rails多态关联正在插入一个额外字段

Ruby on rails Rails多态关联正在插入一个额外字段,ruby-on-rails,polymorphic-associations,Ruby On Rails,Polymorphic Associations,我创建了一个迁移来更改我的数据模型,以便使我的会话模型具有多态性 这是我精简后的文件: # deal.rb class Deal < ActiveRecord::Base has_many :conversations, as: :conversationable end # conversation.rb class Conversation < ActiveRecord::Base belongs_to :conversationable, polymorphic:

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

这是我精简后的文件:

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

# conversation.rb
class Conversation < ActiveRecord::Base
    belongs_to :conversationable, polymorphic: true
end
这将生成错误:

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仍在插入交易id?其他地方是否有我必须删除的协会的残余

在rails控制台中运行相同的代码时,将使用正确的关联创建模型

谢谢。

解决了(多亏了Ryan Biggs)

问题是为了重置我的应用程序,我打电话

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

在迁移和种子设定之间没有足够的时间重新加载列信息。

您确定它在您认为的地方失败了吗?听起来像是一个过时的固定设备文件。在Deal类中是否有一个旧的关联,用于没有
as
选项的对话?@firien:是的!我查看了日志并追踪到了那一行。@tihorn:我也有这个想法-这是该类中对话的唯一关联。你确定要运行迁移(在测试数据库中)吗?如果是的话,你能展示一下吗?
rake db:drop && rake db:migrate && rake db:seed