Can't make EF Code First work with manually changed data base c# ef-code-first entity-framework


I've added two new properties to my domain model class and two properties to a data table accordingly. Then I tried to launch my mvc web application and got

The model backing the 'EFDbContext' context has changed since the database was created.  
Consider using Code First Migrations to update the database  

Having read the following posts:

MVC3 and Code First Migrations

EF 4.3 Automatic Migrations Walkthrough

I tried to Update-Database through Package Manager Console, but got an error

Get-Package : Не удается найти параметр, соответствующий имени параметра "ProjectName".
C:\Work\MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:611 знак:40
+     $package = Get-Package -ProjectName <<<<  $project.FullName | ?{ $_.Id -eq 'EntityFramework' }
+ CategoryInfo          : InvalidArgument: (:) [Get-Package], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,NuGet.PowerShell.Commands.GetPackageCommand

The EntityFramework package is not installed on project 'Domain'.

But the Entityframework is installed on project Domain. I removed it from references, deleted package.config and sucessfully reinstalled EF. But Update-Database still returns same error. Update-Database -Config does as well

What am I doing wrong?


Many thanks to Ladislav Mrnka, I'll try to rephrase my question. As far as I changed my data table manually, I am not expected to use migration. But how can I now make EF work with manually edited domain model class and data table?

5/23/2017 10:24:38 AM

Accepted Answer

Try to add this to startup of your application (you can put it to App_Start):


It should turn off all logic related to handling the database from EF. You will now be fully responsible for keeping your database in sync with your model.

4/2/2013 11:53:13 PM

Popular Answer

I had the same problem and this is how I fixed the issue.

I dropped table __MigrationHistory using sql command and run the update-database -verbose again.

Apparently something was wrong with this automatic created table.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow