Update-Database command is not working in ASP.Net Core / Entity Framework Core because object in database already exists

后端 未结 2 1164
逝去的感伤
逝去的感伤 2020-12-05 15:47

I was updating my database by the command line, but then I manually updated one of my tables.

This seems to have disrupted my ability to update-database. I receive

相关标签:
2条回答
  • 2020-12-05 16:40

    Use Alter column instead AddColumn in up() function

        migrationBuilder.AlterColumn<bool>(
            name: "IsActive",
            table: "Advertisements",
            nullable: false,
            defaultValue: true);
    

    Or

          public override void Up()
          {
            AddColumn("dbo.Products", "Description", c => c.String(maxLength: 50));
          }
    

    asp.net migration

    You can remark some parts in up function if you dont want to full effect to database.

    If your migration command angried for making those. Reset and rebase migration. How: Delete migration content both from visualstudio and sql and add-migration again and update-database

    0 讨论(0)
  • 2020-12-05 16:43

    First, that is not EF 6, it is EF Core. There is no -IgnoreChanges currently in EF Core (see here) but you can achieve the equivalent by commenting out all the code in the Up() method and applying the migration. This will take a snapshot of the current model state so that subsequent migrations will only include changes from that point forward.

    So if you just made some incremental model change and you don't have this initial baseline you may need to remove those changes, apply the baseline migration, then add your changes back and add a 2nd migration.

    0 讨论(0)
提交回复
热议问题