Update-Database is obsolete - Visual Studio 2015 Update 3 - entity-framework

I've done the upgrade for Visual Studio 2015 Update 3, One project is using ASP.Net Core but only for front end JS and CSS using gulp etc. I've just tried to run migrations on the project with migrations and get the following:
Update-Database is obsolete. Use Apply-Migration instead.
Using project 'ProjectName'
Build started...
Build succeeded.
Using start-up project 'MyProject'.
Using application base 'pathlocation'.
Using application configuration 'pathlocation'\Web.config'
Using data directory ''pathlocation'\App_Data'
Using assembly 'My.dll'.
Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 'EntityFramework.Commands' or one of its dependencies. The system cannot find the file specified."
I can't see that I've upgraded to EF 7, and I've uninstalled and reinstalled EF 6 in the project. Any suggestions as to what I'm missing?

I'm sure this was something to do with .Net Core messing up the tooling. To resolve I ran VS as admin. Removed all the EF 7 references in the packages.config in the .Net Core project. Then uninstalled and reinstalled EF 6 through Package Manager Console:
Uninstall-Package EntityFramework -Force
Install-Package EntityFramework -Pre

Using EntityFramework 7? Did you set your dnvm?
first you have to run from the cmd of your project folder this command:
dnvm upgrade
Then try again to use migration, but only from the cmd, and using the dnx command.
Example:
"dnx ef migrations add Initial"
more info: here

Related

How can I call Add-Migration without parameters

I have .net Core 3.1 solution with WebApi and Persistance projects. WebApi is the solution's startup project, Persistance is where DbContext is defined. After a lot of reading and trying stuff, I still cannot achieve the following:
WebApi stays as the solution's startup project.
Migrations folder with all the migrations classes is in the Persistance project.
Migrations can be generated from VS Package Manager Console by typing Add-Migration <migration_name> without any additional parameters like -Project or -StartupProject.
No need to change selection in the Package Manager Console Default project dropdown.
I wanted to achieve the same result but on MAC OS. Because Visual Studio on Mac is not like Window's, We use CLI commands. In my case I had Migration Classes in another project and startup was Api project just like you so i added this to my terminal :
alias migrationfortest='dotnet ef migrations add $1 --project /Users/user/Projects/test-web/Test.Infrastructure'
and you can call this simply by typing migrationfortest "YOURMIGRATIONNAME"
NOTE : For CLI command tools you should add This

Where to run "dotnet ef scaffold" for a new console application?

Trying to create a new console application in Visual Studio accessing an existing SQL Server database. Would like to use EF Core to scaffold models from the database.
MicroSoft's "Getting Started" instructions seem way off. They suggest using NuGet console and running
Scaffold-DbContext "Server=...." Microsoft.EntityFrameworkCore.SqlServer
This does nothing.
One source suggests running "dotnet ef dbcontext scaffold "server=....", but this errors out with:
CategoryInfo: NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException
If I'm running dotnet ef shouldn't I been a command prompt, rather than PM console? But in which folder? Running in the project folder errors out with no executable found matching "dotnet-ef". Note that this is a console application (not ASP) and does not have Project.json, etc...
Did you install EF Nuget Package ?
Install-Package EntityFramework
https://www.nuget.org/packages/EntityFramework

Unable to add Migration to Entity Framework 7

I downloaded a sample Asp.net 5, Mvc 6, EF 7 project from internet. It is working fine, but when I try to add Migrations using console it says
Please run "Dnu restore" to generate a new lock file.
I ran this inside the src/projectName folder on console, If I try to run
dnx ef command its still says the same error.
How can I resolve this error ?

Add-Migration throws error with no configuration found

When I try to create a new migration using EF Code-First the package manager console gives me an error saying: 'No migrations configuration type was found in the assembly 'Project.DataAccess'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).'
I've previously used this method on THIS project successfully and the project do have a Configuration file with all the correct inheritance.
I also tried specifying all the parameters -Name, -StartupProjectName etc. but no change. When trying to re-enable migrations VS is not successful creating the Configuration with inheritance from my context-class.
Any suggestion on this issues? Using EF 4.3.1 and Code-First
This problem was resolved by installing EF 4.3.1 using the Package Manager Console. I had done a manual upgrade and for some reason that didn't do the trick.

The term 'Update-Database' is not recognized as the name of a cmdlet

I am using EF5 beta1 and while I was able to run the "Update-Database" before. Now that I shut down Visual Studio, I cannot get it to run. I get the following error:
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:16
+ Update-Database <<<< -verbose
+ CategoryInfo : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have tried to re-install EF5b1 and while was successful (already installed), the 'Update-Database' still does not work.
Can anyone help???
The solution is to close the Package Manager Console, close Visual Studio and then reopen them.
Rebooting also worked most of the time, but not always.
If you use Entity Framework:
Error Message:
"Error Message (from the Update-Database command in the PMC):
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."
Solution:
Exit Visual Studio. Reopen project and try again.
For more information please visit: Advanced Entity Framework 6 Scenarios for an MVC 5 Web Application (12 of 12)
For anyone who is using .Net Core and EntityFrameworkCore:
You will need to install Microsoft.EntityFrameworkCore.Tools package to resolve this issue.
Read more here: https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
Reinstalling the nuget package fixed this issue for me
ie, execute
Install-Package EntityFramework -Version 5.0.0
in the package manager
Sometimes when I load VS, I see this in my package manager console:
Value cannot be null.
Parameter name: path1
I have no idea what causes that yet but it seems that something goes wrong during the start-up of the Powershell console which interrupts the registering of specific modules, such as the EF powershell extensions. You can just manually load it however:
Import-Module .\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1
Make sure you replace 6.1.1 with whatever your current version of Entity Framework is.
you will get this error when the EF tools are not installed properly.
try the below command in Nuget package manager
//Uninstalls and install the same Version of EF
Update-Package "EntityFramework" -reinstall
If you still face the same issue.
create a new Web Project and run the below command in nuget.
(Note : no need to create the new Project in the same solution or
same location.)
// This will update EF to latest version(including the tools)
// if you want to use specific version , use the -version flag.
Update-Package "EntityFramework"
Once this is done, chcek your original project and you can delete the newly created project.
Just restart Visual Studio, it'll solve the problem. Works for me.
Install Microsoft.EntityFrameworkCore.Tools solved the issue for me, used nuget packages
I solved this by uninstalling and reinstalling Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Tools
I had this same problem, and the origin of it was on my path name, I had on my path a directory name with straight brackets, like this: C:\[PROJ]\TestApp.
When I removed the brackets, to C:\PROJ\TestApp, it started to work just fine...
Just ReOpen visual studio is work for me
For me the problem was the Nuget version.
uninstall Nuget Package Manager.
restart Visual Studio.
installed new version of Nuget Package Manager.
then re-start Visual Studio again.
This problem seems to happen when you open the project directly from File Explorer. Try starting VS first and then opening the project - worked for me. I'm guessing this is about access to paths.
Most of the time those beta versions have some issues, also if Entity Framework failed to load and also this can happen if you are install the Microsoft.EntityFrameworkCore.Tools globally. try to install it locally into your project
. you can try these steps until you fix the issue. and remember this method is not to fix the issue this is the other way to do this.
cd in to your project directory. not the sln directory to the project directory.
then dotnet ef to find out that you have correctly install the Entity Framework.
then use dotnet ef migrations add "ReplaceThisWithSomeText" command. And this will create new migration.
then use dotnet ef database update to update the database.
Migrations Overview. This will helps too..
Windows commands - cd
(This Is for EFCore projects)
If the other answers don't work (VS 2017): clear the NuGet cache, restart VS, then restore the packages.
I found that it was due to a corrupt package. I had installed Automapper when it was already installed. It was only clear that this package was corrupt when I tried to install another package.
Removing the corrupt package solved this issue for me.
You can then reinstall automapper. The issue was with version 5.4, I am now happily on 6.0.
For me it turns out EntityFramework core was not installed on my project (because i started with blank project). So installing EntityFramework package resolved the problem. Sometimes if EntityFramework installation failed then try to install individual packages one by one
E.g.
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design
Microsoft.EntityFrameworkCore.Tools
I solved by updateing Package Manager Console.
I was not getting Update-Database in Package Manager Console. Then i restart several time. Also restart Windows.
Then I download new one from nuget and then it was solved.
I had this problem in Visual Studio 2015 and resolved it by updating the version of Nuget.
Tools -> Extensions and Updates -> Updates -> Visual Studio Gallery
Simple fix for me was to make sure there was a dash between update and database, like this: update-database and use lowercase. It may be coincidental, but when I did this in Packet Manager Console, the database actually updated and I got the done message rather than the not recognized as the name of a cmdlet, function, script file error.
I started having the same issue after I accidentally opened a Visual Studio solution with Visual Studio 2015 instead of 2017. The project worked just fine before that mishap. It was an older project with EF 5.0 and not EF Core.
I tried everything suggested - restarted Visual Studio countless times, cleaned up NuGet cache, deleted everything in packages folder, reinstalled EF 5 for the project - no good, add-migration was not recognized. If I upgraded EF to 6, it started to recognize the commands, but I did not want to upgrade yet. So, as soon as I reverted back to EF 5, the problem returned.
The only thing that finally saved me was to do the following:
close Visual Studio
delete everything from packages folder
delete .vs folder in the root of your solution. This folder is usually hidden, you have to turn on Show hidden files and folders setting or check Hidden items in folder View tab
start Visual Studio and open your solution. It will ask to restore NuGet packages, agree to it.
Now EF commands finally started working again.
In my case:
Reload project did not help
Restart VS did not help
Restart computer did not help
Reinstal EF did not help
But I found an article where suggestion was to manualy import missing EF package, using PM Conole:
Import-Module .\packages\EntityFramework.X.X.X\tools\EntityFramework.psm1
And this solution solved my problem.
In my case restarting Visual Studio (many, many times) did not work, then as I was looking elsewhere I found a message on the output terminal:
The current .NET SDK does not support targeting .NET Core 2.2. Either
target .NET Core 2.1 or lower, or use a version of the .NET SDK that
supports .NET Core 2.2.
So I installed the required version of .NET Core and the command ran successfully.
I had this problem in VS 2019 with an existing project using EntityFramework 6.3.0. This project had some strange version changes done to it over a period of time, and nothing would get it working. I believe I tried every suggestion listed here with no luck.
Finally, updating to the pre-release version of EntityFramework (currently 6.4.0-preview3-19553-01) did fix the problem, by running this in the Package Manager Console: Update-Package EntityFramework -prerelease. I'm hopeful that when this version is released live in the next few weeks it will work properly.
In my case, I did the following:
- restored missing NuGet packages by clicking "Restore" button on top of the Package Manager Console
- restarted Visual Studio
- run update-database
Restoring NuGet package didn't help me.
I had to reinstall package manager - https://visualstudiogallery.msdn.microsoft.com/4ec1526c-4a8c-4a84-b702-b21a8f5293ca
For me the problem was the Nuget version.
I removed and re-installed Nuget then re-started Visual Studio and then all started working.