【问题标题】:PG::UndefinedTable: ERROR: relation does not existPG::UndefinedTable: 错误: 关系不存在
【发布时间】:2013-11-05 16:37:16
【问题描述】:

只是在玩构建一个 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”参考在哪里找不到。似乎有东西挂在活动记录中,但不知道从哪里开始。

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

【问题讨论】:

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


    【解决方案1】:

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

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

    所以 Rails 认为afe 的复数形式是aves

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

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

    【讨论】:

    • 谢谢!永远不会想到这一点。巧合的是,我用相同的默认复数形式拼错了模型。
    猜你喜欢
    • 2016-03-18
    • 2020-05-08
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2021-02-05
    • 2017-11-16
    • 1970-01-01
    相关资源
    最近更新 更多