dotnet ef database update not working for specific migation

0

I am working on dotnet core developing a WebApi and have the following project structure in my VS Solution:

 Solution Project
    |-Project.Data
    |-Project.Entities
    |-Project.WebApi
    |-Project.WebApi.Test

Inside the Project.Data, I have the migrations folder with the initial files that were created when enabling, adding and updating the DB the first time.

Migrations
|-20190712XXXXX_InitialDataBaseModel.cs
|-DataContextModelSnapshot.cs

Then, I updated the Budget property on my Model and executed the following code on the dotnet CLI:

C:\[Solution folder + Project.Data path]> dotnet ef migrations --startup-project ../Project.WebApi add UpdatingBudgetColumn

That worked OK. The proper migration file was created:

Migrations
    |-20190712XXXXX_InitialDataBaseModel.cs
    |-20190726XXXXX_UpdatingBudgetColumn.cs --> This one
    |-DataContextModelSnapshot.cs

However, when trying to update the DataBase:

dotnet ef database update --startup-project ../Project.WebApi 20190726XXXXX_UpdatingBudgetColumn

I am getting the following error:

info: Microsoft.EntityFrameworkCore.Migrations[20402]
      Applying migration '20190712144448_[InitialDatabaseModel'.
Applying migration '20190712XXXXX_InitialDataBaseModel.cs'.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TABLE [TableA] (
          [Id] Int NOT NULL IDENTITY,
          [Description] Varchar(50) NOT NULL,
          [Budget] char NOT NULL,
          CONSTRAINT [PK_TableA] PRIMARY KEY ([Id])
      );
System.Data.SqlClient.SqlException (0x80131904): ***There is already an object named 'TableA' in the database.***
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

I understand the error and why is happening. EF is executing the first migration.

My question here is: Why is the Entity Framework Core executing a different migration other than the one that was specified? (20190726XXXXX_UpdatingBudgetColumn)

c#
.net-core
ef-code-first
ef-core-2.0
ef-core-2.1
asked on Stack Overflow Jul 27, 2019 by MikePR

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0