我在尝试将旧的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
取消对Section.create(...)表示迁移无法完成。
下面是从耙分贝输出:迁移--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
而且注释掉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
后,我已经试过这另一台计算机上,并且它的工作原理。相同版本的rake,同一版本的ruby和rails被冻结。
耙--version:rake, version 0.8.7
,红宝石-v:ruby 1.8.6 (2010-02-05 patchlevel 399) [i686-darwin10.3.0]
,导轨-v:Rails 2.3.8
人有什么想法?
你愿意解释为何这已经解决了这个问题,或是您发现该解决方案! – 2012-02-18 13:53:10