ruby-on-rails - Rails5迁移:表没有外键
问题描述
将我的 Rails 4.2 应用程序迁移到 Rails 5 后,当我尝试从新数据库迁移时,出现以下错误
表“目标”没有 development_plan 的外键
以下是重要的迁移:
使用 add_reference 创建 foreign_key
class AddDevelopmentPlanToObjectives < ActiveRecord::Migration def change add_reference :objectives, :development_plan, index: true, foreign_key: true end end
删除外键(产生错误)
class DropDevelopmentPlans < ActiveRecord::Migration def change Objective.all.each do |objective| company = objective.owner.company company.cycles.create name: '4Q 2015', begin_at: Date.today, end_at: 1.year.from_now, current: true unless company.current_cycle company.reload objective.update cycle: company.current_cycle end remove_foreign_key :objectives, :development_plan remove_reference :objectives, :development_plan, index: true drop_table :development_plans end end
迁移中断remove_foreign_key :objectives, :development_plan
有人遇到过这个问题吗?这也发生在其他类似的迁移中......
解决方案
推荐阅读
- jenkins - 在 Jenkins Groovy 管道中合并两个 yaml 文件
- reactjs - react.js-same 组件传递了不同的 props
- git - 新的 Azure Devops 合并类型“变基和快进”
- c++ - Cxx.jl 在 Julia Complex 和 std::complex 之间转换
- linux - 意外删除了用户的超级用户权限:postgres 10 上的 postgres。如何在不重新安装的情况下将其取回?
- javascript - 如何显示一天到当前日期?角2+?
- javascript - window.screen.width 和 height 是以 CSS 像素还是实际屏幕像素返回的值?
- apache - 带有否定条件规则的 RewriteCond?
- node.js - 完成其他动作后显示 index.html
- c# - 使用 MemoryStream 写入大文件时出现 OutOfMemory 异常