我在db:reset期间丢失迁移时遇到问题。我的迁移不正确吗?

时间:2014-09-04 20:20:03

标签: ruby-on-rails migration rake

运行db:reset

时出现此错误
rake aborted!
ActiveRecord::StatementInvalid: PG::DependentObjectsStillExist: ERROR:  cannot drop table seasons because other objects depend on it
DETAIL:  constraint weeks_season_id_fk on table weeks depends on table seasons
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP TABLE "seasons"

我添加的最近一次迁移是......

class AddSeasonIdToWeek < ActiveRecord::Migration
  def change
    add_column :weeks, :season_id, :integer, null: false, index: true
  end
end

class AddForeignKeySeasonsToWeeks < ActiveRecord::Migration
  def change
    change_table :weeks do |a|
      a.foreign_key :seasons
    end
  end
end

如何解决此错误需要做什么?

1 个答案:

答案 0 :(得分:0)

尝试在rails 4中使用它:

rake db:rollback

两次

在较旧版本的rails中(可能是3及之前)

rake db:migrate:down

两次