0
votes

I've enabled migrations for my ASP.NET MVC project. Migrations work perfectly on localhost. However I get the following exception after deploying it to the server:

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
View Stack Trace

There are no pending migrations, though. Adding a new migration just creates empty Up() & Down()

What could be the reason it doesn't work on the server? I've tried deleting the migrations folder, re-enabling migrations, deleting the database, and let EF do it afresh. The tables get created, but I end up with that exception.

Update:
Another thing I noticed is, when I delete the migration folder but not the database, and enable migrations, it only adds a Configuration.cs file, when it's supposed to add another file too (initialcreate.cs)

1
which entity framework you are using? Have you tried setting AutomaticMigrationsEnabled = true ?Priyank Sheth
Have you applied the empty migration with update-database? That should align the model with the snapshot.Steve Greene
@SimpleMan I tagged it. If you wanted to know the version it's 6.1.1galdin
@SimpleMan Oh and I dint want to enable automatic migrations, so I dint bother trying it out. I dont think it's a good idea to use automatic migrations on productiongaldin
@SteveGreene just tried, dint workgaldin

1 Answers

-1
votes

This happens when you are doing tow different query on the same list of objects on the same time without using .toList

example :

you can create context and get a list of testObjects then edit one of this objects then save changes

var objectsList = context.testObjects.where(x=>x.whatever=true)
objectsList[0].whatever2="asd"
context.SaveChanges()

the above code will pass the compailer and it will fail while running, to solve this it should be as below

    var objectsList = context.testObjects.where(x=>x.whatever=true).ToList()
    objectsList[0].whatever2="asd"
    context.SaveChanges()