Reputation: 17186
Here's the sequence of events that I've experienced a number of times:
Now I'm in a state where the context can't be used because it gives an error that it needs to be updated.
However, updating results in an error due to the coulmn already being there (duplicate column).
So am I just fundamentally "doing it wrong" or is there some command in the package manager that says, "I updated my database manually and it's now up to date"?
Upvotes: 0
Views: 395
Reputation: 232
To prevent this from appening again and again, you should not add the column manually in the database but instead use update-database to update it.
The correct steps should be:
Upvotes: 0
Reputation: 10416
What's happening is EF doesn't know your migration has been applied yet.
What I've done is in package manager console enter:
update-database -v -f -script
Which generates the script for the migration - then I copy the last line in the generated sql, which adds the data to the __MigrationHistory table, and execute it manually. It looks something like this:
This should sync up your code with the database.
Upvotes: 2