Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't enable migrations for Entity Framework on VS 2017 .NET Core

I just installed VS 2017 and created a new Core project. Inside it, I added:

  • Microsoft.EntityFrameworkCore (1.1.0)
  • Microsoft.NETCore.App (1.1.0)

I also created a folder called Models with a class in it. Then, I went to the Package Manager Console and executed enable-migrations so that VS will create the files needed for me. However, instead of the needed files, I got the following error.

The term 'enable-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What am I supposed to do here?

I seem to be out of luck googling. It's a very unusual combination (Core VS17 and EF) so there's virtually no info on the subject. Some guides talk about editing package.json by hand which is kind of hard because VS 2017 seems to upgrade the Core so that dotnet restore doesn't look for it but rather for a xxx.csproj.

In summary, I'm confused and quite uncertain how to bite the problem.

like image 333
Konrad Viltersten Avatar asked Dec 30 '16 23:12

Konrad Viltersten


People also ask

How do I enable migration in Entity Framework?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.

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.


2 Answers

EF Core does not have Enable-Migrations command anymore. Migrations are enabled "by default". Add new migration with Add-Migration.

Documentation about package manager commands is here

like image 59
Dmitry Avatar answered Sep 28 '22 03:09

Dmitry


I just installed Microsoft.EntityFrameworkCore.Tools, then I tried to execute enable-migrations then I got the following message in VS2017:

Enable-Migrations is obsolete. Use Add-Migration to start using Migrations.

Hope it helps.

like image 26
franco148 Avatar answered Sep 28 '22 01:09

franco148