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

Migrations: Drop generated column should come before dropping the columns it's generated from #25237

Closed
benstevens48 opened this issue Jul 12, 2021 · 1 comment · Fixed by #25238
Assignees
Labels
area-migrations 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

@benstevens48
Copy link

Using EF core 5, I removed three columns from my model, with the third column being of type NpgsqlTsVector and computed from the other two via HasGeneratedTsVectorColumn. When I generated the SQL using migrations, it tried to drop the generated column after the other two. However, PostgreSQL doesn't seem to like this - I guess the generated column is already dropped when the columns it's generated from are dropped. It would be good if the order was changed so the generated column was dropped first.

@roji
Copy link
Member

roji commented Jul 12, 2021

Thanks, this repros for me with SQL Server as well - simply trying to drop two columns, where one is computed and depends on the other, may fail depending on the drop order. We should probably order column drop operations so that computed columns are dropped first.

Repro
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();

public class BlogContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

    static ILoggerFactory ContextLoggerFactory
        => LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0")
            .EnableSensitiveDataLogging()
            .UseLoggerFactory(ContextLoggerFactory);

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        => modelBuilder.Entity<Blog>().Property(b => b.Y).HasComputedColumnSql("X + 1");
}

public class Blog
{
    public int Id { get; set; }
    public int X { get; set; }
    public int Y { get; set; }
}

@roji roji self-assigned this Jul 12, 2021
roji added a commit that referenced this issue Jul 12, 2021
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 12, 2021
@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Jul 12, 2021
roji added a commit that referenced this issue Jul 29, 2021
roji added a commit that referenced this issue Jul 29, 2021
@ghost ghost closed this as completed in #25238 Jul 29, 2021
ghost pushed a commit that referenced this issue Jul 29, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc1 Aug 12, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc1, 6.0.0 Nov 8, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations 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.

4 participants