EF Data migrations won't detect changes when adding new migration

后端 未结 16 1933
情话喂你
情话喂你 2020-12-09 14:53

I am using Entity Framework 5.0 Data migrations along with code first. When i add a new field to my model and execute the following command in the package manager console.

16条回答
  •  无人及你
    2020-12-09 15:09

    It happened to me and nothing worked. Then i did this on my own and everything works now.

    Problem: I created a Model "Cars". And When I create a migration for it using command "add-migartion AddCarModel", a migratoin was created but it was empty. I tried with different names and also tried delete migration's .cs file but nothing worked. Then I did the following:

    Solution: Follow below steps:

    1. Delete all the empty migrations that you created for the Model. (But remember the names of the migrations for step 2)

    2. Also delete those migration entries from "_MigrationHistory" table.

    3. Comment out you line(s) of your model DB context, (in my case it is "public DbSet Cars{ get; set; }")

    4. Clean and Rebuild solution. (Its best that if you batch clean)

    5. Make sure that your update command is working and not throwing errors. (Command: "update-database -verbose")

    6. Now uncomment line(s) that you commented in step 3.

    7. Now create the migration for that model. (I created the migration with same name as before)

    Hopefully it works. :-)

提交回复
热议问题