2013-11-05 105 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

谢谢!永远不会想到这一点。被我巧用同样的默认复数形式拼错的巧合蒙上了一层阴影。 –

相关问题