I have two tables, casino_users
and accounts
.
I want to make casino_users.username
a foreign key that references accounts.email
.
I tried this:
class AddForeignKeyToCASinoUsers < ActiveRecord::Migration[5.2]
def up
add_foreign_key :casino_users, :accounts, column: :username, primary_key: "email"
end
def down
remove_foreign_key :casino_users, column: :username
end
end
but it gives me an error Cannot add or update a child row: a foreign key constraint fails
.
Is there something wrong with the syntax I am using?