question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrations: Column order incorrect in CreateTable when using interfaces

See original GitHub issue

With respect to pull request that is dealing with issue and my duplicate, I can report that it indeed creates proper “CreateTable” code for InitialCreate.cs, but at the same time the code for InitialCreate.Designer.cs is not properly created. This causes table not to be created with proper column order.

This is InitialCreate.cs output (and order of columns is correct):

migrationBuilder.CreateTable(
                name: "UserTask",
                schema: "Configurations",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ClientId = table.Column<byte>(nullable: false),
                    ModuleId = table.Column<int>(nullable: false),
                    TaskId = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: false),
                    ModifiedBy = table.Column<string>(maxLength: 100, nullable: false),
                    LastModification = table.Column<DateTime>(type: "datetime", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserTask", x => x.Id);
                });

This is “InitialCreate.Designer.cs” output (and order of columns is NOT correct):

modelBuilder.Entity("MongoPlus.Domain.Models.Subscription.Configurations.UserTask", b =>
                {
                    b.Property<int>("Id")
                        .ValueGeneratedOnAdd();

                    b.Property<byte>("ClientId");

                    b.Property<DateTime>("LastModification")
                        .HasColumnType("datetime");

                    b.Property<string>("ModifiedBy")
                        .IsRequired()
                        .HasMaxLength(100);

                    b.Property<int>("ModuleId");

                    b.Property<int>("TaskId");

                    b.Property<int>("UserId");

                    b.HasKey("Id");

                    b.ToTable("UserTask","Configurations");
                });

When I run “Update-Database -Context SubscriptionDbContext”, I get table created with column order as coded in “InitialCreate.Designer.cs”, and that means that that issue should be reopened.

Further technical details

EF Core version: 2.1.0 Preview 2 Database Provider: Microsoft SQL Operating system: Windows 10 IDE :Visual Studio 2017 15.7 Preview

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
HEBOScommented, Apr 19, 2018

@ajcvickers I understand your point. Even though, imagine someone with 100 tables (like me) to do that manual sorting. I hope it will be in the next release though. Thanks for the update.

0reactions
smitpatelcommented, Mar 16, 2020

@lajones - 3.1.x is milestone used for next patch release. Issues from 3.1.x are moved exact patch number milestone once merged to branch. Put something in patch milestone only if we know for sure it was fixed in particular patch else just use the major/minor version. In this case 3.1.0. If you don’t see particular release in milestones menu then click on closed and you will find closed milestones there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EntityFramework code first: Set order of fields
I am using EntityFramework with the "Code first" approach with migrations. I have successfully generated tables from my models, but the columns ......
Read more >
Entity Framework Core Migrations
To use migrations in EF Core, you start by defining your database schema ... Then future migrations will be based on an incorrect...
Read more >
Resetting Entity Framework Migrations to a clean Slate
I've found in most cases it's simply easier to blow away the migrations and start with a clean slate from the current schema....
Read more >
Active Record Migrations
Migrations are a feature of Active Record that allows you to evolve your database schema over time. Rather than write schema modifications in...
Read more >
Understanding migrations with Room
Room can handle more than one version increment: we can define a migration that goes from version 1 to 4 in a single...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found