【发布时间】:2016-09-18 21:36:21
【问题描述】:
我有一个叫做section的自连接模型:
class Section < ApplicationRecord
belongs_to :offer
# Self joins:
has_many :child_sections, class_name: "Section", foreign_key: "parent_section_id"
belongs_to :parent_section, class_name: "Section", optional: true
end
带有迁移文件:
class CreateSections < ActiveRecord::Migration[5.0]
def change
create_table :sections do |t|
t.string :name
t.references :offer, foreign_key: true
t.references :parent_section, foreign_key: true
t.timestamps
end
end
end
使用 mySql 很好,但后来我删除了数据库,将它们更改为 postresql(因此它们对 heroku 友好),并创建了新数据库。尝试rails db:migrate 后出现错误提示:
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "parent_sections" does not exist
可能发生了什么? mysql和postgresql中的self join有区别吗?
【问题讨论】:
标签: ruby-on-rails postgresql heroku rails-activerecord