PG :: UndefinedTable:错误:关系不存在

时间:2013-11-05 07:19:08

标签: ruby-on-rails ruby-on-rails-4

只是玩弄建立一个rails应用程序,我很确定我做了一些愚蠢的事情。我跑了一个脚手架,拼错了模型Ave vs Afe。我确信我已经完成并更改了迁移文件和查看文件等中的所有内容,甚至还搜索了“ave”以查看是否遗漏了任何内容。无论如何都进行了迁移,现在我得到了这个:

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索引,架构,甚至擦除了我的迁移并运行rake:db:reset。我的架构,模型和控制器都很干净。那个古老的'ave / aves'参考资料无处可寻。它看起来像挂在活动记录中的东西,但不知道从哪里开始。

这是一款虚拟播放应用,但我真的不想重新开始。我可以强制迁移再次运行(如果我取消删除它们)吗?

1 个答案:

答案 0 :(得分:3)

这与复数规则有关,复数规则是用于制作复数形式的模型名称的规则。

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

所以Rails认为afe的复数是aves

您可以通过在迁移中将表重命名为aves或将其添加到config/initializers/inflections.rb来解决您的问题:

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