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

asp.net-core c# entity-framework visual-studio visual-studio-2017

Question

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.

1
14
12/30/2016 11:09:42 PM

Accepted Answer

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

22
12/30/2016 11:24:09 PM

Popular Answer

As others mentioned before, enable migrations is obsolete and is turned on anyway, and you can use the Add-Migration InitialCreate.

I'll add that you do NOT need to add more packages to the project, as it will already reference the necessary assemblies in the Microsoft.AspNetCore.All metapackage.

You can also use your console (cmd/shell depending on your OS) instead of the PM power shell console. To do so, you need to add a reference to the dotnet tool: edit your project file (right click it and select 'edit .csproj' - and add the following reference in an ItemGroup:

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0"></DotNetCliToolReference>

and then in the console type dotnet ef migrations add InitialCreate

Add Migration in .NET Core

.NET Core CLI



Related Questions





Related

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