Add-Migration : A parameter cannot be found that matches parameter name 'Context'.
At line:1 char:15
+ Add-Migration -Context ManagementSystemContext
+ ~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Migration], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration
I'm trying to add migration to App but I got this error despite using this command:
PM> Add-Migration -Context ManagementSystemContext
I uninstalled EntityFrameWork.tools then reinstalled it and restarted visual studio and still the same error
I had the same problem and I couldn't realize what it is. After 2-3 restarts of the PC and the VS, making the same command
Add-Migration NameOfTheMigration -Context MyContext
it appear something in the lines of
"if you are using EntityFramework or EntityFrameworkCore, make sure that you type EntityFramework\Add-Migration, or EntityFrameworkCore\Add-Migration".
I did that and the migration was on.
So the command line looked like this:
EntityFrameworkCore\Add-Migration NameOfTheMigration -Context MyContext
I'm guessing that there were both, EF and EFCore, so the PMC was confused.
Anyway, this is what worked for me.
After "Add-Migration" command EF first expects the name of the migration.
You can cheek this documentation and code sample to see if you did something wrong.
Also you can try to do it via .net core CLI instead of Package-Manager Console, like:
dotnet ef migrations add MigrationName --context ManagementSystemContext --output-dir Dir
Hope something will help.
If your project has two contexts as well as Multi Startup. You must do the following steps:
1- First, take the project out of Multi StartUp mode and set the project startup to your desired Startup.
Then in the Package Manger Console section, type the following command:
Add-Migration -Context ContextName
NOTE : Your default Project in package manger console must set as your DataAccess class libarary
Related
.Net 5.0.1 has been installed. Prompts "ctrl + ." aren't providing the "usual" fixes. I have run into a complete wall. What am I missing? This error is thrown when I run
dotnet ef migrations add InitialCreate -o Data/Migrations
Starting a new project, and trying to set up the database for authentication. I run the following command in powershell.
dotnet ef database update -Context ApplicationDbContext
and get the following error Unrecognized option '-Context'
So I try running it without the -Context option just to see and get:
More than one DbContext was found. Specify which one to use. Use the '-Context' parameter
for PowerShell commands and the '--context' parameter for dotnet commands.
I also tried running it with --context instead of -context, but get the same error. Any suggestions on why it recognizes that I need that option, but at the same time tells me it doesn't recognize the option?
I also restart powershell.
Instead of using --context ApplicationDbContext have you tried -c ApplicationDbContext
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#aspnet-core-environment
I was having the same problem and instead of using dotnet ef database update -Context ApplicationDbContext, I replaced -Context with -c which worked for me.
I'm taking a course in MVC that was recorded in 2016, so maybe that has to do with this error. It says to open NuGet console and type in "Enable-Migrations" in order to enable Entity Framework. But when I type that I get all sorts of error messages and yes I double-checked to make sure I'm doing everything the instructor is. I tried different versions of EF in Nuget Package Manager and the error messages change but still happen.
PM> Enable-Migrations
Enable-Migrations : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1
+ Enable-Migrations
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Enable-Migrations], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Enable-Migrations
First off, why is this even necessary? From what I've seen of EF and LINQ so far I'd rather code in machine language, but in courses I took before that used EF we never had to do "Migrations" before so I'd like to solve this error message but I don't even see the point of it. I thought I read somewhere that Microsoft in its infinite wisdom has changed the way we do migrations but can't find any updated documentation.
Type following command in package manager console.
dir
or
pwd
pwd show you the path of current directory.
dir list down all folders of current directory. if package manager console is not set to project directory, run
cd "YouProjectDirectory"
and run
Enable-Migrations
If you install required packages in this case entitty framework core packages, it will run successfully.
I installed EF in my soluton:
PM> Install-Package EntityFramework -IncludePrerelease
After that, I am trying to execute enable migration command, but it does not work:
PM> enable-migrations
Error:
No context type was found in the assembly 'MyProjectName'.
Specify the target project (that has the DbContext derived class) from the drop down menu Default Project, or alternatively:
PM> enable-migrations -Project <MyProjectName>
try this command may help.
EntityFrameworkCore\enable-migrations
I am new to Asp.Net Core. While reading Adam Freeman's book on Asp.Net Core (2016)
I have done everything properly prior to my problem, however, I can not create database tables using Update-Database Project manager console command as said in the book. Similar topics did not help me. Here is the error.
Invoke must be called on a background thread.
Update-Database : The term 'Update-Database' 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.
At line:1 char:1
+ Update-Database
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Update-Database:String) [],
Comman
dNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What version of ASP.NET Core did you select when created the project?
Did you add both Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools packages, did you do that via the Nuget manager or by editing your .csproj and what versions of that packages did you add?
In the book he adds packages by editing project.json which is no more supported and is replaced by PROJECT_NAME.csproj.
Make sure your dependencies were added and there are no warning signs (In Solution Explorer, expand your project tree. Check if required packages are listed in Nuget section under the "Dependencies" and there is no yellow warning triangle sign on the item).