2010-06-18 149 views
2

我在尝试将旧的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

人有什么想法?

回答

0

显然使用红宝石1.8.6-p399是罪魁祸首。切换到1.8.6-p369解决了它。

+0

你愿意解释为何这已经解决了这个问题,或是您发现该解决方案! – 2012-02-18 13:53:10

0

您也可以尝试在迁移中定义条形骨骼部分模型。在另一个进程

$ rails console --sandbox 

+0

移植无法找到Section模型的问题?看起来很奇怪,它会在不抛出错误的情况下退出。 – ahlatimer 2010-06-20 04:35:44

+0

我不确定,它只是我在迁移变得奇怪时尝试的东西。模型有关于旧模式的信息 – thomasfedb 2010-06-20 12:54:36

8

你可以从不同的原因看到相同的症状:如果你正在运行的迁移可以挂。退出控制台进程允许迁移完成。

+2

靶心!谢谢! – jibiel 2012-01-20 05:33:28

+0

这个问题解决了我的问题 - 但是我的问题在它接近时间线之前就挂起了,与OP的问题相反。如果控制台已经冻结,我无法退出控制台中的进程--Ctrl + C没有任何影响。必须关闭终端窗口才能杀死进程。一旦我退出另一个终端的沙箱控制台,我的数据库就会被终止 - 回滚/迁移不起作用,因为原来的迁移已经被杀死而没有能力正常死亡。我必须回滚到创建表的迁移,导致在迁移之前出现问题。 – guiniveretoo 2013-06-20 16:24:51

2

我有同样的问题..我发现有其挡在该表进一步查询空闲交易..

运行:

heroku pg:ps 

要查看数据库进程。你将不得不杀死空闲进程:

heroku pg:kill 913 --force -a 

(913是空闲进程的ID - >将其更改为您的需求