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 generate wrong order for DropForeignKey and DropPrimaryKey #2509

Closed
andre-artus opened this issue Jun 30, 2015 · 4 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@andre-artus
Copy link

I changed the name of a column in a small database (on SQL Server 2014) I'm using to test EF7 and used "Add-Migration" to generate the code.

Running "Apply-Migration" I received the following error:

"The constraint 'PK_Address' is being referenced by table 'Meter', foreign key constraint 'FK_Meter_Address_AddressAddressId'"

Looking at the code that was generated I noticed that in the "Up" method the call to "DropPrimaryKey" came before the calls to "DropForeignKey".

migration.DropPrimaryKey(name: "PK_Address", table: "Address");
migration.DropForeignKey(name: "FK_Meter_Address_AddressAddressId", table: "Meter");

Dropping foreign keys before the primary key worked as expected.

IDE: VS 2015 RC
EF: 7.0.0-beta4
Project types: Console & Class Library
Windows 8.1

Not sure what other information may prove useful.

@andre-artus
Copy link
Author

I would like to point out that the same is happening in the "Down" method.

@bricelam
Copy link
Contributor

😄 I fixed that just as you were filing the issue.

@andre-artus
Copy link
Author

Was it an open issue already? I did a search in the issues prior to filing, did not see anything that seemed to fit the bill. Thanks for fixing it, where in the code was the issue?

@bricelam
Copy link
Contributor

bricelam commented Jul 1, 2015

No issue; I found it while adding test coverage. It was an oversight in the ModelDiffer.Sort() method.

@bricelam bricelam modified the milestone: 7.0.0-beta6 Jul 3, 2015
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.0.0-beta6, 1.0.0 Oct 15, 2022
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. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants