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

Generate Asp.net core initial migration for exisitng DB which was used by Asp.net MVC app #6425

Closed
sampathdr opened this issue May 15, 2018 — with docs.microsoft.com · 27 comments
Assignees
Labels
doc-enhancement Pri1 Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

sampathdr commented May 15, 2018

I have a existing Asp.net MVC application. In-order to convert it to a Asp.net Core application, how do I generate DB migration. What I need is upgrade ASP.NET identity tables to ASP.NET Core identity.

EDIT: 7.4K PV <-- Serious customers


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@scottaddie scottaddie self-assigned this May 15, 2018
@scottaddie scottaddie added the Source - Docs.ms Docs Customer feedback via GitHub Issue label May 15, 2018
@scottaddie
Copy link
Member

Please see the guidance provided in the following doc: https://docs.microsoft.com/aspnet/core/migration/proper-to-2x/membership-to-core-identity

Copy link
Author

Hi @scottaddie, My current application is having Microsoft.AspNet.Identity (Asp.net MVC). I want to use that DB with Microsoft.AspNetCore.Identity.

@scottaddie scottaddie reopened this May 15, 2018
@scottaddie
Copy link
Member

@sampathdr Thank you for the clarification.

@blowdart Do you have any resources for migrating Identity tables from ASP.NET 4.x to ASP.NET Core? This detail appears to be missing from our migration guide.

@blowdart
Copy link
Contributor

Nope, not a thing. @HaoK ?

@HaoK
Copy link
Member

HaoK commented May 15, 2018

@ajcvickers are there any general EF 6 -> EF Core migration docs that we can link to here? I don't think we need anything special for the identity migration

Copy link
Author

@HaoK Since some properties are different in Microsoft.AspNet.Identity (EF6) and Microsoft.AspNetCore.Identity (EF Core) we cannot directly apply 00000000000000_CreateIdentitySchema migration on top of current DB. So I think we may need to create a migration manually. Is there any better way to handle this?

@jessebarocio
Copy link

Ping. I am also looking for guidance on how to do this. I have several ASP.NET Identity (EF6) databases that I'd like to migrate since we are moving everything to ASP.NET Core.

@sampathdr
Copy link
Author

@jessebarocio I was able to migrate existing DBs using the following steps.

  • Create a new ASP.net Core project and modify it's ModelSnapshot to match with EF6. After that, you can generate a script for the chnages of EF6 to EF Core.
  • Write a script to update the AspNetUsers table. In ASP.net core identity when authenticating it is used NormalizedEmail, NormalizedUserName columns. So we need to update those two columns using our existing data.

@nato24
Copy link

nato24 commented Sep 10, 2018

+1 for official guidance on migrating the db as well.

Copy link

@sampathdr Any chance you can share the modified ModelSnapshot?

@sampathdr
Copy link
Author

@nguyenquyhy Yes, I can share ModelSnapshot and generated scripts with you. I will send an email to your email.

@AndrewMutation
Copy link

I have an existing Asp.net MVC application with EF6 and an IdentityDbContext. ( Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext )

Is there any way I can use the same database from a .core project that is using EF core.

It seems like there is a lack of compatibility that will force me either remain on the full framework or convert all projects (no budget for this) that use the identity db at the same time.

@jaketollette
Copy link

@sampathdr I'm in the exact same situation. Would you be willing to share your ModelSnapshot and scripts with me as well?

@sampathdr
Copy link
Author

@sampathdr I'm in the exact same situation. Would you be willing to share your ModelSnapshot and scripts with me as well?

Hi Jake, I have sent you an email with DB scripts.

@keirk
Copy link

keirk commented Nov 22, 2018

+1 @sampathdr

Maybe add as a comment to this thread?

@joaorsfonseca
Copy link

+1 @sampathdr
Can you add those scripts here as comment? Thanks

@sampathdr
Copy link
Author

Migration.zip

These are the migration scripts I generated. Feel free to modify them accrding to your requirement.

@AlissonRS
Copy link

I was able to update the schema, however I still had to migrate existing users to use the new password hasher algorithm. The easier (probably safer) option is to ask all users to reset their passwords.

If you don't want to ask users for resetting their passwords, but want to gradually update password hashes to the new algorithm as they authenticate, I posted what I did in this Stack Overflow question.

@CallStackRunner
Copy link

@AlissonRS Hello, Alisson!
When I've been converted one of the projects to use Identity 3 instead of 2nd version, I've done some research about passwords hashes difference and operations compatibility.
I found that implementations of UserManager methods (that are related to the passwords verification) in Identity 3 are able to determine if hashes has been generated by old Identity 2. This is done via so called format marker anaslysis-- the first byte of password's hash. And based on this verification can use either old hashing strategy or new one, no rehashing required.
The same thing is described in docs of CompatibilityMode option of hasher.

So if it's not too late and if prior to Identity 3 you've used default hashing strategy, then I'd suggest you to consider try these compatibility features instead of writing them by hand and force users to reset passwords. It worked well in project which I've converted to use new Identity.
Hope that this is helpful.

@AlissonRS
Copy link

Hi @CallStackRunner

Thanks for your reply. I'm aware of this feature, in fact I tried it, but I think it only works when migrating between .Net Core projects, I tried using this with users created in MVC 5 project and it didn't work.

My guess is that this only works for users created using the Microsoft.AspNetCore.Identity package, which was not the case for my MVC 5 project.

I appreciate your reply.

@CallStackRunner
Copy link

@AlissonRS That's strange. "MVC5 --> Core" conversion was my case (Identity conversion is only a part of it) and users has been created using old packages of Identity.

Well, hopefully this might be helpful for anyone else who will face this task :)

@AlissonRS
Copy link

@CallStackRunner I'll give another try just in case, maybe I did something wrong. I'll post the outcome here.

@AlissonRS
Copy link

@CallStackRunner when I use CompatibilityMode without overriding the PasswordHasher, the login works for existing users, but the hashes are not updated to newest version. Have you faced this situation? I'd like hashes to be rehashed to latest algorithm version.

@CallStackRunner
Copy link

@AlissonRS I don't think that default behavior is to update hash, so it's expected that they aren't updated.
In my case I didn't tried rehashing at all, backward compatibility was enough for my requirements.
According to this article, the supposed way to do this is exactly to implement custom PasswordHasher and return PasswordVerificationResult.SuccessRehashNeeded when necessary.
So if you need to rehash passwords then you're on the right way :)

@ajcvickers
Copy link
Contributor

@Rick-Anderson Is there something specific you want me to address here?

@Rick-Anderson
Copy link
Contributor

@HaoK asked

@ajcvickers are there any general EF 6 -> EF Core migration docs that we can link to here? I don't think we need anything special for the identity migration

If not, I'll close this issue.

@ajcvickers
Copy link
Contributor

@Rick-Anderson We currently have this: https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/index

Plus an issue to make it better: dotnet/EntityFramework.Docs#1180

So closing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Pri1 Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests