When I created a migration file as usual and tried rails db: migrate, I got the following error.
Column user_id
on table entries
does not match column id
on users
, which has type bigint(20)
. To resolve this issue, change the type of the user_id
column on entries
to be :bigint. (For example t.bigint :user_id
).
As instructed, the migration was performed again by specifying bigint as shown below.
class CreateEntries < ActiveRecord::Migration[5.1]
def change
create_table :entries do |t|
t.references :user, foreign_key: true, type: :bigint //Change from integer to bigint
t.references :room, foreign_key: true
t.timestamps
end
end
end```
However, a similar error appeared.
Actually, at this time, three migration files were created at the same time, and an error occurred because the creation date and time of the migration file (room) required to register the above migration file was the last.
I changed the file name to the creation date and time of the room file, and when I ran rails db: migrate again, it passed without problems.