Entity Framework Automatic Migrations Existing Database

独自空忆成欢 提交于 2019-12-01 06:41:44

Folks

The answer to my problem above was helped by this article http://christesene.com/entity-framework-4-3-code-first-with-automatic-migrations/

I had to delete my previous initial migration class, and re-create it.

I had a similar problem.

The cause for me was that the same migration had been run already in the database but under a different MigrationID. I had 201504302005411_InitialCreate but my migration script was called 201505041911076_InitialCreate.

I fixed the issue by renaming the MigrationID in the database to match the one in my code.

I don't quite know how I ended up in the situation but renaming the MigrationID meant the app knew the script had already been run.

if your context is mine: added a new entity class worked on it but, when I tried to migrate it shows this error, try removing that object from db context then run update-database and add that object again and rerun update-database

for example:

public DbSet<CustomizedEmail> CustomizedEmail { get; set; }
public DbSet<KeyWordsForEmail> KeyWordsForEmail { get; set; }
public DbSet<Notice> Notice { get; set; }//remove it>run update-database>
//add again the above entity and rerurn update-database

this works whether you have data or not. in this process you will loose data in that table.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!