I'm trying to use migrations to add a parent table to an existing child table. For eg. I currently have User
table, now I want to add a Department
table that has a 1 to many relationship: Department has many User
.
My questions, in automatic update, can I somehow seed the parent table before adding the FK so I can update all the children to this default seeded Department
? If automatic update cannot do this, how do I accomplish this in code?
What I currently did: Made the FK nullable, created the Parent and seeded it, then update all child User
FK to the parent. But now I cant change the FK not nullable because throws this error: Automatic migration was not applied because it would result in data loss.