Search code examples
databasemigration.net-corecommand-line-interfacevisual-studio-mac

Update Database with Migrations CLI on VS for Mac (DotNet Core 2)


I created the Models of my database on VS for Mac and used terminal for create migrations:

dotnet ef migrations add IntitialMigration

Then, I updated my database:

dotnet ef database update

But after I changed my Models and I created another migration:

dotnet ef migrations add SecondMigration

And tried to update the database:

dotnet ef database update SecondMigration

I received the following error:

There is already an object named 'Emails' in the database.

I've searched and I found a probably solution:

Add-Migration SecondMigration -IgnoreChanges

But this only works at PMC on Windows. I'm using VS for Mac and all the commands are typed on Terminal. Does anybody know how to update a database using Migrations after change the Models?


Solution

  • I found the solution. It seems that on VS 2017 for Windows, when you add a Migration, it is automatically added on the solution. But, on VS for Mac, that doesn't happen. You need to manually add the each new migration to the solution. I created the InitialMigration migration and update it to the database. For some reason I don't know why, I removed the migration from the solution and I created the new SecondMigration migration. That's the reason that all the tables that were on InitialMigration were on SecondMigration too.