Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable migrations in Visual Studio for Mac

Tags:

I have Visual Studio for Mac and I'm trying to learn Xamarin with Azure using the following tutorial: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/server/

At some point, I have to enable EF migrations. The tutorial says: Go to View -> Other Windows -> Package Manager Console.

Unfortunately there is no Package Manager Console in Visual Studio for Mac... so how do you handle things like enable-migrations, add-migration or update-database on the Mac?

like image 673
franswa Avatar asked Jul 28 '17 21:07

franswa


People also ask

How do I enable migrations in Visual Studio?

From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.

How do I migrate in Visual Studio?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.


2 Answers

To run EF on Mac just follow the following.

Open a command line, go to the project folder, and run

dotnet restore

If everything is fine, you should be able to run

dotnet ef

After that you can run commands like:

dotnet ef migrations add initial

dotnet ef database update

like image 180
J T Avatar answered Oct 04 '22 00:10

J T


This is currently supported on Mac.

First you need to install dotnet-ef

dotnet tool install --global dotnet-ef

To install a specific version of the tool, use the following command:

dotnet tool install --global dotnet-ef --version 3.1.4

Add the "dotnet-ef" tools directory on the PATH environment variable.

export PATH="$PATH:/Users/'your user folder'/.dotnet/tools"

Open a command line, go to the project folder, and run

dotnet restore

If everything is fine, you should be able to run

dotnet ef

After that you can run commands like:

dotnet ef migrations add initial

dotnet ef database update

PS: Your solution should not be executing when the dotnet ef command line is trying to run!!!

For People who are not convinced, here a demo of succeed!!! For People who are not convinced, here a demo of succeed!!!

like image 33
G Clovs Avatar answered Oct 03 '22 23:10

G Clovs