2013-11-05 108 views
2

只是玩弄建設一個rails應用程序,我敢肯定,我做了一些愚蠢的事情。我跑了一個腳手架,拼錯了模型Ave vs Afe。我相信我會在遷移文件和查看文件等過程中改變所有內容,甚至搜索'ave'以查看我是否錯過了任何內容。反正跑了遷移,現在我得到這樣的:PG :: UndefinedTable:錯誤:關係不存在

PG::UndefinedTable: ERROR: relation "aves" does not exist LINE 5: WHERE a.attrelid = '"aves"'::regclass^: SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"aves"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum 

Extracted source (around line #17): 

15 # GET /afes/new 
16 def new 
17 @afe = Afe.new 
18 end 
19 
20 # GET /afes/1/edit 

我檢查了我的postgsql指標,模式和甚至擦去我的遷移和運行耙:DB:復位。我的模式,模型和控制器都很乾淨。那個舊的'ave/aves'參考沒有找到。它看起來像掛在積極的記錄,但不知道從哪裏開始。

這是一個虛擬遊戲應用程序,但我真的不想重新開始。我可以強制遷移再次運行(如果我取消刪除它們)?

回答

2

這與多元化規則有關,用來製作複數形式的模型名稱的規則。

ActiveSupport::Inflector.pluralize "afe" 
    => "aves" 

所以Rails的認爲的afe複數是aves

可以,或通過添加這config/initializers/inflections.rb在遷移重命名錶回aves解決您的問題:

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.irregular 'afe', 'afes' 
end 
+0

謝謝!永遠不會想到這一點。被我巧用同樣的默認複數形式拼錯的巧合蒙上了一層陰影。 –

相關問題