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

Sql Server Migrations: Throw when altering IDENTITY #5345

Closed
rowanmiller opened this issue May 12, 2016 · 4 comments
Closed

Sql Server Migrations: Throw when altering IDENTITY #5345

rowanmiller opened this issue May 12, 2016 · 4 comments
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

@rowanmiller
Copy link
Contributor

If you go through the process of changing the ApplicationUser ID type to int, then you will hit issues with EF migrations. On SQL Server, you'll get errors including:

The object 'PK_AspNetUsers' is dependent on column 'Id'.
The object 'FK_AspNetUserRoles_AspNetUsers_UserId' is dependent on column 'Id'.
The object 'FK_AspNetUserLogins_AspNetUsers_UserId' is dependent on column 'Id'.
The object 'FK_AspNetUserClaims_AspNetUsers_UserId' is dependent on column 'Id'.
ALTER TABLE ALTER COLUMN Id failed because one or more objects access this column.

@flagbug
Copy link

flagbug commented Jul 11, 2016

@rowanmiller What would be the best way to do this right now?

@bricelam
Copy link
Contributor

bricelam commented Aug 15, 2016

This will require table rebuilds (issue #329). Even if we managed to drop and recreate all the referencing constraints, the updated primary key columns will not be marked as IDENTITY.

The best workaround for now is to make this change before creating the database, delete the model snapshot and migrations files, then re-add the CreateIdentitySchema migration.

@bricelam bricelam removed this from the 1.1.0 milestone Aug 15, 2016
@divega
Copy link
Contributor

divega commented Aug 15, 2016

Triage: the reson this was traiged for 1.1.0 is that we want to give users more information when this situation happens.

@divega divega added this to the 1.1.0 milestone Aug 15, 2016
@bricelam
Copy link
Contributor

bricelam commented Aug 16, 2016

I'm still not sure how to provide additional information in this scenario.

Options:

Invalid options:

  • Throw when altering with IDENTITY. This is valid if the column was added with IDENTITY.
  • Throw when altering a key. This is valid provided you manually rebuild the dependent constraints.

@bricelam bricelam changed the title Migrations: Changing ASP.NET Identity key to int fails to migrate Sql Server Migrations: Throw when altering IDENTITY Sep 7, 2016
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 7, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.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

5 participants