The model did not contain the original author information (user). You are about to add a user.
To migrations
add_reference : model, :user, index: true, foreign_key: true
So I'd like to add author information. Then should I write belongs_to
separately on the original model?
Also, I want to give the default value only during migration, but can I give the default value as user_id like default: 10
?
It's a self-answer.
You can write bellongs_to separately. Migration is a task to add columns to DB, and belongs_to is necessary for use with model.user
, so you can proceed with the migration by adding both migration and belongs_to
to the code.
The default value is not included. After the migration, I put the value in the DB separately.
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
576 Who developed the "avformat-59.dll" that comes with FFmpeg?
922 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.