如何在Rails迁移中跳过不存在的父记录并添加外键约束

时间:2019-02-26 04:34:33

标签: ruby-on-rails foreign-keys rails-migrations

我正在一个Rails应用程序上,我需要为Rails迁移中的现有列添加一些外键。

int character=BoxOfChocolates[2][4].treatNumbers();

运行上述迁移时,出现以下错误:

  

StandardError:发生错误,所有以后的迁移都被取消:

     

Mysql2 :: Error:无法添加或更新子行:外键   约束失败(class AddFkRefsToPackages < ActiveRecord::Migration[5.2] def change add_foreign_key :packages, :orders, name: :index_packages_on_order_id add_foreign_key :packages, :locations, name: :index_packages_on_location_id end end myproject_development,约束   #sql-1_5a外键(index_packages_on_location_id)   参考quote_route_idquote_routes)):更改表id添加   约束quote_legs外键   ({index_quote_legs_on_quote_route_id)参考文献location_idlocations

通过Rails控制台,我们观察到在父(位置)中没有id,但在子(包)中将其作为parent_id(location_id)引用。

我们尝试过:

id

除上述内容外,我们可以选择添加CASCADE_DELETE还是有任何方法清除/跳过这些记录?

0 个答案:

没有答案