mercredi 11 avril 2018

how to rename foreign key while creating tables

i have two models for user and account. It is a one to one relationship so i have belongs_to :user in account model.

I have migration script for account table i have t.belongs_to :user, index: true

When i run rake db:migrate it creates column user_id. I want the name as user_account_id.

I tried creating another migration script to change foreign key name from user_id to user_account_id and it works but how can change foreign key name while creating tables so i dont have to add another migration script?

Thanks

Aucun commentaire:

Enregistrer un commentaire