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

后端 未结 2 1280
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.

    0 讨论(0)
  • 2021-01-18 07:35

    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)
        {
        }
    }
    
    0 讨论(0)
提交回复
热议问题