gpt4 book ai didi

ruby-on-rails - PG::UndefinedTable: 错误:关系 "----' 不存在

转载 作者:行者123 更新时间:2023-11-29 14:18:28 26 4
gpt4 key购买 nike

我在开发环境中使用 SQlite,在生产环境中使用 Postgre。

在开发过程中一切正常。但是当我尝试重置和迁移生产数据库时,我收到了以下消息:

PG::UndefinedTable: ERROR:  relation "priceranges" does not exist
...
FOREIGN KEY ("pricerange_id")
REFERENCES "priceranges" ("id")

我的 field 模型:

belongs_to :pricerange, :class_name => "PriceRange" 

我的价格范围迁移:

class CreatePriceRanges< ActiveRecord::Migration[5.0]
def change
create_table :price_ranges do |t|
t.string :price_description
t.timestamps
end
end
end

有什么想法吗?

最佳答案

您在迁移中创建的表名称是 price_ranges,而不是 priceranges。除非您覆盖 PriceRange 模型中的表名,否则您在 Venue 上的 pricerange 关联将查找名为 price_range_id< 的外键,而不是 pricerange_id。我会建议坚持惯例,并建立你的协会:

belongs_to :price_range # automatically uses class PriceRange, and foreign key `price_range_id`

关于ruby-on-rails - PG::UndefinedTable: 错误:关系 "----' 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39085628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com