Reputation: 20935
I am using Visual Studio 2015 and dotnet core and trying to develop an EF Core Code First project using Sqlite and this documentation / tutorial, which also uses Sqlite => NET Core - New Database
When I try to add an initial migration from the command line ( I am CD-ed into the folder that my data model project is located in) by issuing the following command
dotnet ef migrations add InitialMigration
...I get the following Error.
No project was found. Change the current working directory or use the --project option.
I even tried using the --project
option like so.
> dotnet --project "C:\Shiva\EF\EFCFSqlite.Data.xproj" ef migrations add InitialMigration
but that gives the following error.
Unknown option: --project
.NET Command Line Tools (1.0.0-preview2-003131)
Usage: dotnet [host-options] [command] [arguments] [common-options]
I noticed that the documentation is using .csproj
file whereas my Project is showing a xproj
file. Also the docs mention something about not using project.json
anymore :(
Here's my project.json
file.
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.1",
"Microsoft.EntityFrameworkCore.Sqlite.Design": "1.1.1",
"NETStandard.Library": "1.6.1"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet":"1.0.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
What has changed? Do we have no choice but to Install Visual Studio 2017 and start from scratch?? Is project.json
and all this other stuff no longer honored?
Upvotes: 69
Views: 132845
Reputation: 790
You are most likely in the directory that your IDE project is in. You need to change directories to the directory with the actual .Net project in.
In my case, I am using Rider, rather than Visual Studio, and on macOS. So there is an outer MyProject directory containing the Rider project file .idea
, and things like .git
, and .gitignore
. Then there is an inner MyProject/MyProject directory containing all the .Net project stuff such as your source code.
So in my case, it was simply
cd MyProject
Then it worked. It created a Migrations
directory containing the migration.
Upvotes: 0
Reputation: 11
You should be sure current directory on Context file's folder. You can check with use "dir". And that was different, so change directory with using "cd".
Upvotes: 1
Reputation: 27
I know this is old but it also helps to check the version of your .net so that your install the required version. Check the accepted answer here: Command dotnet ef not found
Upvotes: 0
Reputation: 981
for mac os i did like this.. working fine for me.
dotnet ef database update -c ApplicationDbContext
Upvotes: -1
Reputation: 171
If you're getting this error while working with the ABP Framework and trying to add new migration:
C:\Users\rushas\source\repos\MyProject\aspnet-core>
for cmd commanddotnet ef migrations add InitialMigration --context MyProjectDbContext
Upvotes: 0
Reputation: 547
Just simply use this command.
Add-Migration InitialCreated -c bodoContext
No need to worry.
Upvotes: 2
Reputation: 43
Add references Microsoft.EntityFrameworkCore.Design and Microsoft.EntityFrameworkCore.Tools
Then run:
dotnet-ef migrations add InitialCreate --project ProjectName
or
dotnet ef migrations add InitialCreate --project ProjectName
Upvotes: -1
Reputation: 73
Apparently, it may sound funny, but in my case when I was getting this error I had the server-side of the app running. Basically, make sure that your app is not running at all when trying to create migrations. As I said, for me that was the cure. Might be a bit of advice for those who couldn't fix it by following the marked answer.
Upvotes: 1
Reputation: 5201
It simply Means that
YOU ARE NOT IN CURRENT PROJECT DIRECTORY
I was facing the same issue when scaffolding existing database of MySql using this.
Command I was executing:
dotnet ef dbcontext scaffold "Server=123.1.1.1;Uid=abc;Pwd=abc;Database=myDB;Connection Timeout=20;Persist Security Info=False;Port=3306;Allow User Variables=True;Connect Timeout=120;" MySql.Data.EntityFrameworkCore -o Models
Causing the same error , then I checked current working directory inside package manager console and found incorrect.
In my case
Mean I was not in current project directory then after switching directory
cd SSGCApp
Now you are in project directory all good to run the Command.
Upvotes: 56
Reputation: 425
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.Design
Edit
and then add the following to the ItemGroup
that contains PackageReference
nodes<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
(You can find the latest version by finding it in the Nuget Package manager)
cd {path where your csproj file resides}
(this is important)dotnet ef migrations add InitialMigration
Upvotes: 12
Reputation: 1713
sometimes you need to change the current directory in console/terminal eg:
PM> cd E:\Projects\CrossTest\
PM> dotnet ef migrations add InitialMigration
and Align your package versions. Either use preview1 packages or preview2. Mix of those are not supported.
Upvotes: 123
Reputation: 1519
The dotnet-ef command has moved.
You will need to add a reference to Microsoft.EntityFrameworkCore.Tools.DotNet AND Microsoft.EntityFrameworkCore.Design to your dependencies in project.json, then add Microsoft.EntityFrameworkCore.Tools.DotNet to the tools section and you should be good to go.
Cited from: http://errummwelluhh.blogspot.com
Upvotes: 0
Reputation: 1658
Just faced similar issue. Fixed by downgrading to 1.0.0-preview3-final
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",
}
and changing --project param to --startup-project
dotnet ef --startup-project <PATH_TO_PROJECT_DIRECTORY> migrations add <MIGRATION_NAME>
In global.json I also downgraded version to
"sdk": {
"version": "1.0.0-preview2-003131"
}
This might be a temp workaround before migrating to csproj.
Upvotes: 2
Reputation: 360
Instead of:
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet":"1.0.0"
},
try:
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": {
"version": "1.0.0-preview3-final"
}},
Upvotes: 15