Ruby on rails I';在db:reset期间,我无法删除迁移。我的迁移是否不正确?

Ruby on rails I';在db:reset期间,我无法删除迁移。我的迁移是否不正确?,ruby-on-rails,migration,rake,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:

运行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 AddSeasonIdToWeek

class AddForeignKeySeasonsToWeeks

我需要做什么才能克服此错误?

尝试在rails 4中使用此选项:

rake db:rollback
两次

在旧版本的rails中(可能是3或更早版本)


两次

另一种选择是只使用sql手动将子记录中的外键更新为null,然后您可以删除父记录。您可以只向关系添加
dependent::delete
,这将在删除时使外键为null当您说“两次”时,您的意思是运行命令两次,背对背?您是否使用“外国人”gem允许外键迁移?
rake db:rollback
rake db:migrate:down