Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Migration error - object refreence, MigrationsDomainCommand

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.

like image 885
user2922040 Avatar asked Oct 26 '13 03:10

user2922040


People also ask

How do I enable-migrations in Visual Studio?

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.

What does enable-migrations do?

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.

How do I turn off migration in EF core?

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.


2 Answers

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.

like image 50
Gigi2m02 Avatar answered Sep 29 '22 18:09

Gigi2m02


I saw someone saying that you need to run Visual Studio as an administrator. I tried it and it worked.

like image 42
modeeb Avatar answered Sep 29 '22 19:09

modeeb