What is the equivalent of the -IgnoreChanges switch for entity-framework core in CLI?

.net entity-framework entity-framework-core


With Visual Studio one can run the command

Add-Migration InitialCreate -IgnoreChanges 

in the Package Manage Console when creating the first migration of the model of an existing database with Code First workflow.

What is the equivalent for CLI? The add command would be like this:

dotnet ef migrations add InitialCreate

but what about the ignore switch?

11/8/2018 2:43:05 PM

Accepted Answer

In the absence of any other way, one can empty the Up and Down method blocks of the migration of all code and run database update.

public partial class Initial : Migration
    protected override void Up(MigrationBuilder migrationBuilder)


    protected override void Down(MigrationBuilder migrationBuilder)
11/8/2018 3:52:02 PM

Popular Answer

My project has an existing database and we wanted to use migrations, since we do not have IgnoreChanges in EFCore what i did was ran the command

Add-Migration -Name InitialMigration in the package manager console of visual studio, this created the InitialMigration.cs file for me

And then I commented out the code in the Up function in the InitialMigration.cs and ran the command update-database in the package manager console.

Doing this creates a table named dbo.__EFMigrationsHistory in your database which keeps a track of your migrations.

Later when you add or remove the column, just run the Add-Migration command which will create a new migration for you make sure you validate the Up and Down function both to make sure everything looks ok and is as expected.

Once you validate, run the update-database function which should run the new migration script for you.

For now this is how we went ahead with our implementation.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow