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

Dan*_*pin 3 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
Run Code Online (Sandbox Code Playgroud)

我检查了我的 postgsql 索引、模式,甚至清除了我的迁移并运行了 rake:db:reset。我的架构、模型和控制器都很干净。旧的“ave/aves”参考无处可寻。它看起来像是在活动记录中挂断了但不确定从哪里开始。

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

zwi*_*pie 6

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

 ActiveSupport::Inflector.pluralize "afe"
   => "aves"
Run Code Online (Sandbox Code Playgroud)

所以Rails的认为的复数afeIS aves

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

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'afe', 'afes'
end
Run Code Online (Sandbox Code Playgroud)