I have a MVC 4 project and recently upgraded to EF 6.0. I have only one project which contains the models and dbcontext. I was unable to enable migrations, the errors are as follows:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue[T](Project project, String propertyName) at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory) at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName) at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Object reference not set to an instance of an object.
Googling for an answer for past 2 days, nothing seems to work. Please help me.
From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.
In order to use code-based migration, you need to execute the following commands in the Package Manager Console in Visual Studio: Enable-Migrations: Enables the migration in your project by creating a Configuration class.
Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.
I had the same issues this week when my senior developer updated the solution to EF6.
After a 'Get latest' from source control, the migrations weren't working anymore. A Visual Studio restart solved that problem. Probably the EF5 libraries were still in memory.
I saw someone saying that you need to run Visual Studio as an administrator. I tried it and it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With