I have redesigned my class scheme many times since started the project I'm working on.
At first I didn't know about data annotations, so I have migration1
, where my Ids have no DatabaseGenerated.Identity
option and migration4
where they already have it.
Turns out that EF doesn't work this way (https://entityframework.codeplex.com/workitem/509 as for EF5), so when I added some seed data, it threw an exception
Cannot insert the value NULL into column 'primarykeycolumn', table 'tablename'; column does not allow nulls. INSERT fails.
What's really interesting is when I deleted all existing migrations and scaffolded new one from scratch, seed method ran without any problems.
So I have a question: do I need to do it any time I make changes to scheme such as adding data annotations like Identity
or is there a way to save my previous migrations? Because dropping and recreating db in real-life can result in a huge data loss, which I want to avoid.