Cannot Migrate Database

PocketPixie 21 Reputation points
2024-09-16T16:17:42.4466667+00:00

Hello all,

I am having issue updating the migration of my database. I am currently using .NET 9.0. I have modified one of my files to include the following:

protected override void Up(MigrationBuilder migrationBuilder)

{

migrationBuilder.UpdateData(

table: "DiaryEntries",

keyColumn: "Id",

keyValue: 1,

column: "Created",

value: new DateTime(2024, 9, 16, 12, 6, 6, 691, DateTimeKind.Local).AddTicks(2342));

migrationBuilder.UpdateData(

table: "DiaryEntries",

keyColumn: "Id",

keyValue: 2,

column: "Created",

value: new DateTime(2024, 9, 16, 12, 6, 6, 691, DateTimeKind.Local).AddTicks(2642));

migrationBuilder.UpdateData(

table: "DiaryEntries",

keyColumn: "Id",

keyValue: 3,

column: "Created",

value: new DateTime(2024, 9, 16, 12, 6, 6, 691, DateTimeKind.Local).AddTicks(2646));

}

Unfortunately when I do add-migration AddedSeedingDataDiaryEntry

followed by update-database

it comes with this error message:

at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'ApplicationDbContext' has pending changes. Add a new migration before updating the database. This exception can be suppressed or logged by passing event ID 'RelationalEventId.PendingModelChangesWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.

How do I update the database to help with pending changes? I have already added the migration and I see the file there, but this error message makes it look like the migration was never added.

Developer technologies | .NET | Entity Framework Core
{count} votes

1 answer

Sort by: Most helpful
  1. MikeyQiaoMSFT-0444 3,310 Reputation points
    2024-09-18T09:59:37.7033333+00:00

    Hi,PocketPixie

    Entity Framework Code isn't really my thing.

    I've found the following link for you, the content inside might be of help to you.

    https://stackoverflow.com/questions/70555317/multiple-level-properties-with-ef-core-6

    Regards

    Mikey Qiao


    If you're satisfied with the answer, don't forget to "Accept it," as this will help others who have similar questions to yours.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.