When I run Add-Migration from Package Manager Console everything is alright. But I get an error when run it in .NET Core command-line interface.
I also got error in dotnet ef database update
Am I missing something or making a mistake?
Is your DbContext file in the Infrastructure Class library? If not, you can use the following command :
dotnet ef migrations add RemoveSeedData --project THE PROEJECT PATH CONTAINING DBCONTEXT
Example :
dotnet ef migrations add RemoveSeedData --project ../MyProject.Data
Related
I'm attempting to generate a migration for EF, with the following command:
dotnet ef migrations add InitialCreate -p .\MyProject.csproj --output-dir ./Dal/Migrations
The MyProject.csproj project has a dependency to another project in the same solution: MyDependency.csproj.
When I run the command above, I get a FileNotFoundException saying that the file MyDependency.dll was not found.
How can I instruct EF to reference the proper dependencies when attempting to create the migrations?
I ended up manually copying the binaries of the referenced project to the build output folder of the main project, then launch the EF migration generation command:
cp ..\MyDependency\bin\Debug\net5.0\*.* .\bin\Debug\net5.0\
dotnet ef migrations add InitialCreate -p .\MyProject.csproj --output-dir ./Dal/Migrations
Still, I wonder if there's a better way to do the job.
Command:
dotnet ef migrations add addListModel --project <path to the .csproj file>
Error:
error MSB4068: The element <NDepend> is unrecognized, or not supported in this context.
Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
Dotnet core version 2.1
I am building asp.net core web application using full .NET framework 4.6.1 template like this-
My project.json shows-
"frameworks": {
"net461": { }
},
I wanted to use EF6 (not EF core), hence install entity framework using NuGet package manager using this command-
Install-Package Entityframework
Project.json added this entry-
"EntityFramework": "6.1.3",
When I am trying to create a DBcontext and model using below Command:
Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLENAME
It throws below error:
Scaffold-DbContext : The term 'Scaffold-DbContext' 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.
As I understand (since I have Powershell v3.0 and .NET core 1.0.1), rest of the EF tools and dependencies are missing in my project.json. So which are tools and dependencies I need to add in my project.json to use EF6 (not EF core)?
Some of the options I can see are like below. But not sure which one is right for EF6
"EntityFramework.MicrosoftSqlServer":
"EntityFramework.SqlServer":
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
I didn't get what you mean by using core in .net but if you are targeting you project to old .net you need to install compatible version.
For .net 4.8 following package version will work:
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.1.25
I have framework version set to: dnx46 in project.json.
Also have the following packages:
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final"
}
However when I got into running enable-migrations command I get the following:
The term 'enable-migrations' is not recognized as the name of a cmdlet
Does anyone know how I get EF migrations running in latest .NET?
This is what worked for me to solve this issue:
Run:
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
In project.json add this (if not there already) to the "tools" section:
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final",
Useful reference: https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html
As ErikEJ mentioned, there is no "enable-migrations". You will need to use "Add-Migrations" instead. See official docs for EF Core's Powershell commands here: http://docs.efproject.net/en/latest/cli/powershell.html
There appears to be a bug in NuGet and Package Manager Console in some versions of Visual Studio. If cmdlets are not recognized after adding the Commands package, try restarting VS.
Also, dnx commands will not be supported after RC1. New (forthcoming) dotnet tooling will be available for RC2. See https://github.com/aspnet/EntityFramework/issues/3925
The only way I managed to get EntityFrameworkCore.Tools (which includes Add-Migration) working with the latest EF Core & VS 2015 was to manually call the init script from the Package Manager Console like so:
PM> %UserProfile%\.nuget\packages\Microsoft.EntityFrameworkCore.Tools\1.0.0-preview1-final\tools\init.ps1
To add a new migration in EF7 use this command :
dnx ef migrations add YourMigrationUniqueName
There is no "enable-migrations" command in EF Core (EF7).
Just use "add-Migration"
Currently EF migrations are not supported out of the box:
https://github.com/aspnet/EntityFramework/issues/4497
I Haved the same probleam, i was using the PowerShell for the comand, but he work in Package Manager Console.
Try to run in ->
Tools -> NuGet Package Manager -> Package Manager Console
While starting my asp.net 5.0 application + EF 7 RC1. I get the message to apply model change so I click the apply button but then I get an error with the message I should run "dnx ef database update" from the command line. So I did on the CMD within my project with my migration folder and the context class.
But I get this error:
Error: Unable to load application or execute command 'EntityFramework.Commands'. Available commands: web, ef.
In the project.json there I have put the:
"commands": {
"ef": "EntityFramework.Commands"
}
What am I missing?
You're missing a reference to EntityFramework.Commands in that project. Add a reference to it in project.json.