Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
qsdfplkj opened this issue May 25, 2020 · 1 comment · Fixed by #21040
Closed

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

qsdfplkj opened this issue May 25, 2020 · 1 comment · Fixed by #21040
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@qsdfplkj
Copy link

qsdfplkj commented May 25, 2020

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)

@roji
Copy link
Member

roji commented May 25, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants