9
votes

I am trying EntityFrameworkCore in Visual Studio Code and I want to run "Update-Database" and "Add-Migration' commands, but there is no Package Manager Console in VSCode. what to do?

3

3 Answers

7
votes

Visual Studio Code doesn't support the running of Package Manager Console commands. That integration is only available in the Visual Studio. You will have to use the Command Line Interface (CLI) instead:

http://www.learnentityframeworkcore.com/migrations/commands/cli-commands

4
votes

Yes, you can always do this with vscode.

Install the dotnet ef tool by running the preceding command.

dotnet tool install --global dotnet-ef

You should get a message in the command prompt as below.

You can invoke the tool using the following command: dotnet-ef Tool 'dotnet-ef' (version '5.0.3') was successfully installed.

Now you should be able to run any ef commands. For example,

dotnet ef database update

That will give you a response as below.

Build started...

Build succeeded.

Done.

Just sharing this, as some people might have not installed the ef tools.

2
votes

You can absolutely run EF commands from the VS Code terminal. First make sure you are in the Directory that contains your "appsettings.json", your "Program.cs" etc.

Try executing dotnet ef database update You might get "Run "dotnet tool restore" to make the "dotnet-ef" command available." Run that: dotnet tool restore Then try dotnet ef database update again

Adding a migration:

dotnet ef migrations add ChosenMigrationName