什么会导致此迁移挂起?

ahl*_*mer 3 ruby-on-rails

我正在尝试将旧的1.2.6 Rails应用程序升级到2.3.8,并且我遇到了一些迁移问题.也就是说,如果我在迁移中有类似ModelName.create(:foo =>"bar")的内容,则迁移不会完成.它没有达到无限循环或任何东西.它只是拒绝完成迁移.

这是一些示例代码.

这有效:

class CreateNewsArticles < ActiveRecord::Migration
  def self.up
    create_table :news_articles, :force => true do |t|
      t.string  "name"
      t.string  "image"
      t.text    "body"
      t.boolean "featured", :default => "0"
      t.integer "position"
      t.timestamps
    end
    # Section.create(:name => 'News Articles', :controller => 'news_articles', :description => 'Add, edit, and delete news articles.')
  end

  def self.down
    drop_table :news_articles
    Section.find_by_name('News Articles').destroy
  end
end
Run Code Online (Sandbox Code Playgroud)

取消注释Section.create(...)意味着迁移永远不会完成.

这是rake db:migrate --trace的输出:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
   -> 0.0531s
Run Code Online (Sandbox Code Playgroud)

在评论出Section.create之后

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  CreateNewsArticles: migrating =============================================
-- create_table(:news_articles, {:force=>true})
   -> 0.0479s
==  CreateNewsArticles: migrated (0.0481s) ====================================

** Invoke db:schema:dump (first_time)
** Invoke environment 
** Execute db:schema:dump
Run Code Online (Sandbox Code Playgroud)

我在另一台计算机上试过这个,它确实有效.相同版本的rake,相同版本的ruby和rails被冻结.

rake --VERSION : rake, version 0.8.7, ruby​​ -v : ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.3.0], rails -v:Rails 2.3.8

有人有主意吗?

fea*_*ool 9

您可以从不同的原因中看到相同的症状:如果您正在运行,迁移可能会挂起:

$ rails console --sandbox
Run Code Online (Sandbox Code Playgroud)

在另一个过程中.退出控制台进程可以完成迁移.

  • 靶心!谢谢! (2认同)