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

后端 未结 2 1300
Happy的楠姐
Happy的楠姐 2021-01-18 07:00

With Visual Studio one can run the command

Add-Migration InitialCreate -IgnoreChanges 

in the Package Manage Console when creating the firs

2条回答
  •  甜味超标
    2021-01-18 07:30

    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.

提交回复
热议问题