如何在Rails中使用级联删除将列添加为外键

问题描述 投票:0回答:1

我有两个桌子一种产品和另一种用法

Product
#  id                  :integer          not null, primary key
#  product_name        :string           not null
#  plan_id             :string
#  plan_name           :string

Usage
#  id              :integer          not null, primary key
#  quantity        :float
#  date            :date

要在使用中将product_id添加为外键

我正在尝试运行迁移

 def change
    add_reference(:usages, :products, foreign_key: { on_delete: :cascade })
 end

不存在外键约束中引用的错误列“ product_id”,]

我有两个表,一个产品,另一种用法,产品#id:整数不为null,主键#product_name:string不为null#plan_id:string#...

ruby-on-rails ruby-on-rails-4.2
1个回答
0
投票

解决方案的ref_name应该是单数

© www.soinside.com 2019 - 2024. All rights reserved.