efcore: After upgrade from 2.1 to 2.2, creating a new migration adds unexpected DropForeignKey, DropUniqueConstraint, DropColumn statements

Issue summary

We have been using EF Core for 6 months now, and recently, after updating our project from 2.1 to 2.2, any new migration script has a ton of unexpected DropForeignKey, DropUniqueConstraint, DropColumn statements. Neither of the Keys, UniqueConstraints or Columns exists, so running this on the DB obviously fails. But this prevents us from creating new migrations.

I cannot come up with a small reproducible example, but I will try to share some patterns of the statements I noticed.

Issue details

All DROP COLUMN statements happen only for classes that are owned by parent classes that are owned by a grandparent (it has to be double owning, single not enough). By owning I mean something like that:

builder.OwnsOne(
                nav => nav.MyCustomChildProperty, action =>
                {
                    action.OwnsOne(nav => nav.MyCustomGrandChildProperty);
                }
            );

In all such scenarions, in my migration scripts, I would see DROP COLUMN statements like such:

  • MyCustomChildProperty_TempId
  • MyCustomChildProperty_TempId1 (this one is a maybe)
  • MyCustomChildProperty_MyCustomGrandChildProperty_TempId
  • MyCustomChildProperty_MyCustomGrandChildProperty_TempId1 (this one is a maybe)
  • MyCustomChildProperty_MyCustomGrandChildProperty_TempId2 (this one is a maybe)
  • … and even weirder ones like:
  • MyCustomChildProperty_MyCustomGrandChildProperty_MyCustomChildPropertyClassMyCustomClassId Basically the pattern here is take class name of grandparent, add it to a grandparent class name, etc… and after reaching end, add Id to it.

I haven’t tried to find a pattern for the other two types of statements (DropForeignKey, DropUniqueConstraint), but this seems that it should be related.

I tried deleting all of my migrations and creating a single fresh migration, and everything looks there as expected, therefore it seems that this is some bug that happens only if you already have some old migration scripts and trying to add a new one.

I have raised an SO question for this as well with no success.

Possibly relevant versions

We were running using 2.1 versions of dotnetcore andef core`. Currently, my versions are:

  • dotnet --version = 2.2.102
  • dotnet ef --version = 2.2.1-servicing-10028
  • Database Provider: Microsoft.EntityFrameworkCore.SqlServer, v2.2.1
  • OS: Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 21 (17 by maintainers)

Most upvoted comments

@smitpatel I’d like to do at least the initial work. Once that’s done we can see who’ll handle the perf optimization (avoiding boxing).

@bricelam Go ahead. I’m working on https://github.com/aspnet/EntityFrameworkCore/issues/18628, it’ll likely take me all the time left for 3.1