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

Foreign keys removed from owned tables when excludedFromMigrations set to true #23137

Closed
OliDow opened this issue Oct 29, 2020 · 0 comments
Closed
Labels
area-migrations area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@OliDow
Copy link

OliDow commented Oct 29, 2020

Repo to view and reproduce error.
https://github.com/OliDow/EFToolingExcludeFromMigrationsIssue

First issue
If you are working on a project that deals with a owned relationship but you are not the service that is in charge of the tables you will set excludefrommigrations as true. However this does not work as intended, it will remove all of the foreign keys related to that relationship and then not readd them again.

  • If this is done a single time the downside will be no foreign key constraints
  • if a second migration is added it will attempt to remove a key that does not exist and result in an exception.
    public partial class Dependent2 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Children_Parent_ParentId",
                schema: "Dependent",
                table: "Children");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Children_Parent_ParentId",
                schema: "Dependent",
                table: "Children");
        }
    }

Second issue
When creating migrations on owned relationships the tooling will add a line trying to call a method that doesn't exist to each entity, currently this will need updating manually in both the migration file and the snapshot file
image

Attached Repository should demonstrate both of these issues

@ajcvickers ajcvickers added this to the 5.0.x milestone Oct 30, 2020
AndriySvyryd added a commit that referenced this issue Nov 3, 2020
Don't generate DropForeignKey or data operations for excluded tables.
Don't set excluded from migrations to false if it was not specified.

Fixes #23137
AndriySvyryd added a commit that referenced this issue Nov 3, 2020
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 3, 2020
@AndriySvyryd AndriySvyryd removed their assignment Nov 3, 2020
@AndriySvyryd AndriySvyryd modified the milestones: 5.0.x, 5.0.1 Nov 3, 2020
AndriySvyryd added a commit that referenced this issue Nov 10, 2020
AndriySvyryd added a commit that referenced this issue Nov 12, 2020
@ajcvickers ajcvickers changed the title EF Tooling - Foreign keys removed from owned tables when excludedFromMigrations set to true Foreign keys removed from owned tables when excludedFromMigrations set to true Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
Development

No branches or pull requests

3 participants