销毁对已删除迁移的引用

时间:2013-09-11 17:39:57

标签: ruby-on-rails heroku

好吧,我犯了一个大错,并在本地删除了几个迁移(现在我知道更好了)。这成为一个问题,因为现在当我尝试部署到heroku时,我收到以下错误:

Running `rake db:migrate` attached to terminal... up, run.3430
rake aborted!
Multiple migrations have the name CreateScores
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:978:in `validate'

起初这让我感到惊讶,因为我只有一个名为“创建分数”的迁移 - 但后来我注意到了这一点:

Drews-MacBook-Pro:quiz drewwyatt$ rake db:migrate:status

database: /Users/drewwyatt/Sites/Ruby/Rails/quiz/db/development.sqlite3

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20130828212225  Create answers
   up     20130828212306  Create questions
   up     20130829210727  Create quizzes
   up     20130829211302  Remove quiz id from question
   up     20130829212349  Create assignments
   up     20130829234338  Create employees
   up     20130829234541  Add role and active to employee
   up     20130830032801  ********** NO FILE **********
   up     20130902183412  ********** NO FILE **********
   up     20130902183530  Create scores
   up     20130902230036  Add indexes to score
   up     20130904210011  Create positions
   up     20130904212007  Add position to employee
   up     20130905161805  Create quiz assignments

我的假设是其中一个已删除的迁移也被命名为“创建分数”。所以我的问题是,如何摆脱2次删除的迁移?

2 个答案:

答案 0 :(得分:2)

要获得快速解决方案,您可以逐个迁移每个版本的迁移文件,而不是一次迁移所有迁移,例如

rake db:migrate:up VERSION=version_of_the file

请检查此链接:Run a single migration file

答案 1 :(得分:1)

回滚到正在迁移的版本,您将收到错误。你可以这样做,如下所示。

rake db:migrate:down VERSION = 20130829234541

如果root / db / migrate文件夹中存在,则删除与错误相关的任何引用。

然后再次运行迁移。没关系。