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

Db Migration Fails when trying to update. #6378

Closed
groogiam opened this issue Aug 20, 2016 · 1 comment
Closed

Db Migration Fails when trying to update. #6378

groogiam opened this issue Aug 20, 2016 · 1 comment

Comments

@groogiam
Copy link

Steps to reproduce

I added a new table to my database which participates in a one to many relationship with another table. When I scaffold the migration I get the following code.

public override void Up()
        {
            CreateTable(
                "TemplateDefinition",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        BusinessDomainId = c.Guid(nullable: false),
                        InputViewModelId = c.Guid(),
                        SystemName = c.String(nullable: false, maxLength: 255),
                        TemplateMarkup = c.String(),
                        InvariantId = c.Guid(nullable: false),
                        DisplayName = c.String(nullable: false, maxLength: 255),
                        Description = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("BusinessDomainDefinition", t => t.BusinessDomainId, cascadeDelete: true)
                .ForeignKey("ViewModelDefinition", t => t.InputViewModelId)
                .Index(t => t.BusinessDomainId)
                .Index(t => t.InputViewModelId);

        }

Upon applying this migration I get the following error.

Applying explicit migrations: [201608200256366_MigTemplateDefs].
Applying explicit migration: 201608200256366_MigTemplateDefs.
The Foreign Key on table 'TemplateDefinition' with columns 'InputViewModelId' could not be created because the principal key columns could not be determined. Use the AddForeignKey fluent API to fully specify the Foreign Key.

The BusinessDomainDefinition table was created in a previous migration and has a primary key. There are also several other 1 to many child tables created in the initial migration that are applied without the same error.

The issue

EF Migrations should be able to apply this without an issue. It is a simple 1 to many relationship. If I delete all migrations and re scaffold the entire database the update works without any problem.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
Stack trace:

Further technical details

EF Version 6.1.3
Visual Studio 2015 Community

Other details about my project setup:

@divega
Copy link
Contributor

divega commented Aug 23, 2016

This issue was moved to dotnet/ef6#53

@divega divega closed this as completed Aug 23, 2016
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants