0
votes

I know there are many topics about this error message but none of them is similar my problem. I am using Entity Framework 6. I have changed my entity and I have to run add-migration and then update-database. but when I run add-migration the newly created class public partial class Test: DbMigration contains two empty Up and Down methods. so when I run update-database it does not make any changes on the database. and I am get this error always.

I am getting this error when I run update-database. I think the problem occur becasue UP and Down methods are empty and no changes are made into the database when I run update-database.

2

2 Answers

0
votes

in Application_Start() Method in Global.asax.cs file write as first line this

Database.SetInitializer<YourDBContext>(null);
0
votes

For those that want to know what was the problem. When you create a MVC 5 project with Idenity, it adds ApplicationDbContext class to connect to the database. I had created another DBContext for my entities. When I changed my entities and run add-migration it affected only chnages that was made for those ootb entities which belong to ApplicationDbContext not my DBContext. and When I run update-database it does not update my entities. I added all my entities to ApplicationDbContext and run add-migration then update-database and it solved the problem.