I have studied several questions on this topic today. I know that, I can use t.references
in migration to add a reference. But, If a table has non-integer primary key, how do I add reference to that column?
I have a table with this definition
create_table :sessions, id: false do |t|
t.string :session, primary_key: true, limit: 10
t.timestamps null: false
end
How do I add a reference to the session
column (the name doesn't matter here), which is a string from another table migration. I tested with t.references
but that just add an integer column. I know that I can use add column
. But how to do that without from create_table
method directly?
Clarification for duplicate flag
This question is flagged as duplication of this question, but it is actually not. Because I am not asking about setting up table with non-default non-integer primary key, because I already set up that table. I am asking about referencing this type of table from another table.