我创建了迁移:
class AddVisibleToStocks < ActiveRecord::Migration[5.2]
def change
add_column :stocks, :visible, :boolean
end
end
我进行了迁移。一切都很好,但当我需要回滚时,我看到了错误:
rake db:rollback
== 20180404150630 AddVisibleToStocks: reverting ===============================
-- remove_column(:stocks, :visible, :boolean)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "stocks"
我的股票模型:
class Stock < ApplicationRecord
belongs_to :category
has_and_belongs_to_many :providers
end
接着我进行了另一次迁移,但立即将其回滚——结果还是一样。
出了什么问题?