I created two references in a migration that are aliases for a reference to my User table:
class CreateInvitations < ActiveRecord::Migration[5.0]
def change
create_table :invitations do |t|
t.references :owner, references: :user, foreign_key: true # the owner
t.references :invitee, references: :user, foreign_key: true # the invitee
t.references :core_bot, foreign_key: true # the associated page (core_bot_active)
t.string :email
t.string :token
t.timestamps
end
end
end
In my User model:
has_many :invitations, foreign_key: :owner_id
has_many :invitations, foreign_key: :invitee_id, dependent: :destroy
In my Invitation model:
belongs_to :owner, class_name: :User
belongs_to :invitee, class_name: :User
Everything works well in development but when I try to migrate in production with Heroku heroku run rake db:migrate
, I get the following error:
PG::UndefinedTable: ERROR: relation "owners" does not exist : CREATE TABLE "invitations" ("id" serial primary key, "owner_id" integer, "invitee_id" integer, "core_bot_id" integer, "email" character varying, "token" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, CONSTRAINT "fk_rails_59e24979a9" FOREIGN KEY ("owner_id") REFERENCES "owners" ("id") , CONSTRAINT "fk_rails_00204dc74b" FOREIGN KEY ("invitee_id") REFERENCES "invitees" ("id") , CONSTRAINT "fk_rails_34505bdb65" FOREIGN KEY ("core_bot_id") REFERENCES "core_bots" ("id") )
I tried without references: :user
but I get the same error.
Any idea what's wrong here?