rake db:最近一次迁移的回滚挂起

时间:2013-04-04 00:13:46

标签: ruby-on-rails-3

我有一个rails应用程序,我最初在第3轨道写入,并在大约一个月前升级到rails 3.1.10。我刚刚创建了故事和标签之间的habtm关联,以及相关的数据库迁移。

class Story < ActiveRecord::Base

  belongs_to    :user
  has_and_belongs_to_many :tags, :uniq => true

end

class Tag < ActiveRecord::Base

    has_and_belongs_to_many :stories, :uniq => true

end

class CreateTags < ActiveRecord::Migration
  def change
    create_table :tags do |t|
      t.string :name

      t.timestamps
    end
  end
end

class CreateStoriesTags < ActiveRecord::Migration
  def change
    create_table :stories_tags, :id => false do |t|
      t.references :story, :tag
    end

    add_index :stories_tags, [:story_id, :tag_id]
  end
end

最后,这是相关的schema.db:

  create_table "stories", :force => true do |t|
    t.string   "title"
    t.integer  "user_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "stories", ["user_id"], :name => "index_stories_on_user_id"

  create_table "stories_tags", :id => false, :force => true do |t|
    t.integer "story_id"
    t.integer "tag_id"
  end

  add_index "stories_tags", ["story_id", "tag_id"], :name => "index_stories_tags_on_story_id_and_tag_id"

  create_table "tags", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

我迁移了数据库,然后在控制台中使用了关联。现在我想回滚迁移,以便在tags表中添加一些额外的列。 (我知道我可以简单地创建一个新的迁移,但我仍然想要理解为什么我会遇到这个问题。)现在,当我将rake db:rollback插入控制台时,这里是初始输出:

[nw0.0.1master (development)]$ rake db:rollback
==  CreateStoriesTags: reverting ==============================================
-- drop_table(:stories_tags)

到目前为止一切顺利,但随后rake任务才挂起。 。 。用了几个小时。如果我在这里ctrl-c输出到控制台:

^Crake aborted!
An error has occurred, this and all later migrations canceled:

Interrupt: : ROLLBACK
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:605:in `async_exec'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:605:in `block in execute'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract_adapter.rb:245:in `block in log'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activesupport-3.1.10/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract_adapter.rb:240:in `log'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:604:in `execute'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `rollback_db_transaction'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `rescue in transaction'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:182:in `transaction'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/transactions.rb:208:in `transaction'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:742:in `ddl_transaction'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:686:in `block in migrate'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:671:in `each'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:671:in `migrate'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:553:in `down'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:627:in `move'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:541:in `rollback'
/.rvm/gems/ruby-1.9.2-p290@rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/railties/databases.rake:232:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)

值得注意的是,由于这个应用程序是从rails 3.0开始的,所有早期迁移都使用较旧的Class.up Class.down方法来定义迁移。此外,当我第一次尝试挂起时,我将CreateStoriesTags迁移切换为使用updown实例方法,但所有内容仍然挂起。

更新和答案

我注意到PGAdmin3 Workbench也挂了。所以,我重新启动了Mac,现在回滚正在查找。

1 个答案:

答案 0 :(得分:3)

原来我的数据库服务器出了问题。简单的重启修复了问题