rails g migration add foreign key code example
Example: rails g migration foreign key optionnal
#MODEL
belongs_to :author, optional: true
#MIGRATION
t.references :author, foreign_key: true
#MODEL
belongs_to :author, optional: true
#MIGRATION
t.references :author, foreign_key: true