Rails 5迁移 - 缺少的参考
问题描述:
我不知道我错过了什么 - 我最近将我的Product
类别从静态枚举移到了表中,所以我需要修改引用。Rails 5迁移 - 缺少的参考
我会结合我的许多移民是建立Tasks
表,我需要有对Product
表的引用现在
class CreateTasks < ActiveRecord::Migration[5.1]
def change
create_table :tasks do |t|
t.string :task_name
t.text :comment
t.datetime :task_start_date
t.datetime :task_end_date
t.references :project
t.timestamps
end
end
end
class AddDocumentsToTasks < ActiveRecord::Migration[5.1]
def change
add_reference :tasks, :document, foreign_key: true
add_reference :tasks, :product, foreign_key: true
end
end
class AddClientIdToTasks < ActiveRecord::Migration[5.1]
def change
add_foreign_key :tasks, :client, foreign_key: true
end
end
的新鲜模式(减少)
我实际上并不知道t.integer "product"
来自任务文件夹。我已经看遍了。
它是目前打破所有集成/播种因为一个警告,如: ActiveRecord::AssociationTypeMismatch: Product(#69974683871240) expected, got 1 which is an instance of Integer(#13017840)
我想这是很简单的东西,我失踪,但因为它是非常多余的代码我不太知道为什么它的工作原理对于文档/项目,而不是产品。
以防万一: 产品迁移
class CreateProducts < ActiveRecord::Migration[5.1]
def change
create_table :products do |t|
t.string :product_name
t.text :product_description
t.references :client
t.references :task
t.timestamps
end
end
末**
更新
不回答这个问题,直到我完全理解为什么,但似乎我误解了rails db:reset
做。一旦我放弃/创建/迁移/种子一步一步地完成整个数据库结构,并且新模式发生。
它似乎db:重置是只有使用我的Schema.rb文件中的逻辑。
答
您的schema.rb
用作迁移的缓存。因此,如果您更改已迁移的迁移文件,则不会显示这些修改。您必须删除您的schema.rb
内容,然后重置您的数据库。
你的问题还在吗? –