class Test < ActiveRecord::Migration[5.2]
def change
add_reference :tags, :owner, foreign_key: { to_table: :users }, default: nil, null: true
end
end
class Test < ActiveRecord::Migration[5.2]
def up
add_reference :tags, :owner, foreign_key: { to_table: :users }, default: nil, null: true
end
def down
remove_reference :tags, :owner, foreign_key: { to_table: :users }, default: nil, null: true
end
end
add_reference :tags, :owner
と指定した場合、カラム名は owner_id
となる。