Skip to content

Migration creates constraint before altering table. 5.0.0-preview.4.20220.10 #21037

Closed

Description

@qsdfplkj

The constraint is added before the column is added in the migration..

public partial class AlterTable : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateCheckConstraint(
            name: "Check",
            table: "People",
            sql: "LEN(TRIM([Name])) > 0");

        migrationBuilder.AddColumn<string>(
            name: "Name",
            table: "People",
            type: "nvarchar(max)",
            nullable: true);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropCheckConstraint(
            name: "Check",
            table: "People");

        migrationBuilder.DropColumn(
            name: "Name",
            table: "People");
    }
}

Steps to reproduce

Alter the a table by adding a property in this case Name and add a constraint on the configuration.

5.0.0-preview.4.20220.10

PreviewEFIssues.zip

Further technical details

EF Core version: 5.0.0-preview.4.20220.10
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)

Activity

  1. self-assigned this
    on May 25, 2020
  2. added a commit that references this issue on May 25, 2020
    3bc4efb
  3. roji commented on May 25, 2020

    @roji
    Member

    Thanks for reporting this and for using the previews! I've submitted a fix (which should appear in preview6). In the meantime, as a workaround simply create the column and add the check constraint in two different migrations.

  4. added this to the 5.0.0 milestone on May 27, 2020
  5. added a commit that references this issue on May 27, 2020
    c8dc681
  6. added a commit that references this issue on May 27, 2020
    f244396
  7. modified the milestones: 5.0.0, on Jun 1, 2020
  8. modified the milestones: , 5.0.0 on Nov 7, 2020
  9. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions