Reputation: 13000
When I run my application it says the model backing my context has changed since the database was created.
I added a field to my model like:
public int? LocationId {get;set;}
I added an int
column to the database, and it is nullable.
I understand the database has that _migrationsHistory
table that is now not in sync.
What I have been doing so far in QA is just dropping all the tables and then running the application which just re-creates the database automatically for me.
Now I want to keep the data in the table, how can I fix this issue?
I added the column so it should work, but when it performs the validation during startup if fails.
What options do I have?
Upvotes: 1
Views: 88
Reputation: 538
It sounds like you want to use Code-First Migrations (EF 4.3 and later)
This would allow you to generate migration files based on changes to the model via the Package Manager Console.
you can generate a migration file by using add-migration <name>
, make changes to it if required and use update-database
to manually update.
You can also roll-back to any migration point if you inadvertently break something.
Upvotes: 1