2010-06-18 143 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 - >將其更改爲您的需求