问题
Since EF Core migrated to Microsoft.EntityFrameworkCore.*
(instead of EntityFramework.*
), it seems that the recommended command line to add db migrations is back to add-migration
from package manager.
ef core add migration documentation
However it seems there isn't a package anymore for commands and that the package installation of v 1.0.1 doesn't add any command.
The error message I'm getting when running Add-Migration
is
Cannot execute this command because EntityFramework.Commands is not installed in the startup project 'project name'.
Did I miss something? Is there a new way to add the commands or so? Thanks for your help!
回答1:
In order to use the Package Manager Console commands (e.g. Add-Migration
) on .NET Core projects, your project.json
will need to look something like this.
{
"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
}
The Microsoft.EntityFrameworkCore.Tools
under dependencies
ensures the PowerShell commands get registered. It's "type": "build"
ensures they don't get published with your application. The Microsoft.EntityFrameworkCore.Tools
under dependencies
ensures the dotnet ef
command gets registered (which is called by the PowerShell commands).
来源:https://stackoverflow.com/questions/39751199/entity-framework-core-1-0-1-add-migration