I am using Entity framework Model First approach with MySQL db. I am having a column in the database, but the property is not there in Model. SO now my problem is I need it to be added to Model and get it populated when data is retrieved from DB. SO now my problem is when I add this property to Model I get mismatch error with DB as mapping is missing.
1 Answers
Sounds like you'll have to manually stage a migration, and then update the __MigrationHistory
table with the new model context.
I'm not sure if there is official documentation out there, but I've done this before and here's the simplest way to do it:
- Create a new database, empty.
- Upgrade it to the current model.
- Add the column exactly as it is in the original MySQL db to the model.
- Upgrade the second database to the new model.
- Grab the new row from the
__MigrationHistory
table and copy it to the original database.
You'll be looking for the last row which should have a longer Model
value.
This is a very touchy process, and is not always easy to do. Make sure to test it multiple times on a copy of the production database.
You can also try the method mentioned in this answer: https://stackoverflow.com/a/14286509/4564272
Run: Update-Database -Script
and pull the INSERT INTO [__MigrationHistory]
code and run it manually on the server.
Both of these mean Entity Framework should recognize that the database and the model match. I've done this before when the code first model and database get out of sync, and this process has brought them back into sync.

- 1
- 1

- 5,848
- 1
- 29
- 43