.NET Core Update migration is trying to re-create table again

.net .net-core asp.net-core entity-framework entity-framework-core

Question

I was working on a .net core 3 project code first. In this step I added 2 columns into my tables. Then I made a migration addition to solution via this code (CLI).

dotnet ef --startup-project ../MyApi.Api migrations add actorInfomart

My migration returned this:

public partial class actorInfomart : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
        migrationBuilder.AddColumn<bool>(
            name: "IsSeries",
            schema: "film",
            table: "Movie",
            nullable: false,
            defaultValue: false);

        migrationBuilder.AddColumn<string>(
            name: "ExtInfo",
            schema: "act",
            table: "Actor",
            maxLength: 100,
            nullable: true);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropColumn(
            name: "IsSeries",
            schema: "film",
            table: "Movie");

        migrationBuilder.DropColumn(
            name: "ExtInfo",
            schema: "act",
            table: "Actor");
    }
}

It seems correct. The problem is coming here. When I tried to update migration then I got this error :

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

My migration is trying to create new table in my database. But in migration there is nothing for this. Here is my migration update CLI command.

dotnet ef --startup-project ../MyApi.Api database update actorInfomart

In terminal (I am using Mac) writes

info: Microsoft.EntityFrameworkCore.Migrations[20402]
      Applying migration '20191231100058_Initial'.
Applying migration '20191231100058_Initial'.

How can I apply latest migration? I have 10 migrations between first and last. This is my first problem about migrations.

1
0
3/6/2020 9:28:11 AM

Popular Answer

I saw the problem in my db. Because of truncating '__EFMigrationsHistory' table in DB. The system's behavior is changing into initial migration as no migrations applied.

0
3/6/2020 12:13:17 PM


Related Questions





Related

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