Below I have a migration for the "test" model which uses it's own primary key, a String instead of an Integer.
class CreateTest < ActiveRecord::Migration[5.1]
def change
create_table :test, id: false do |t|
t.string :id, primary_key: true
t.timestamps
end
end
end
Now we have the "client" model that t.references
test.
class CreateClients < ActiveRecord::Migration[5.1]
def change
create_table :clients do |t|
t.references :test, null: false
t.timestamps
end
end
end
The issue is that t.references
assumes it's an integer id.
# == Schema Information
#
# Table name: clients
#
# id :integer not null, primary key
# test_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
This is obviously wrong as Test.id
is a string.
Is there some magic I need to do to have the t.references
"know" that it's a string based on the model or something?
Thanks.
Add this to the migration with the references
:
type: :string
The reference column type. Defaults to :integer.
You can read more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With