问题
I've finished an EF Code First Project with a SQL Express database in a lab environment.
Once the project is done, I've changed the DB Connection String to connect to the new Production SQL Express Database.
Now, I have got the Model tables generated automatically but the AspNetUsers, AspNetRoles, AspNetUserRoles etc. are not generated automatically. I am a new learner and I need your help to know how I can get the tables back in the database.
If I do update-database from the Package Manager Console, I get:
Error Number:4902,State:1,Class:16
Cannot find the object "dbo.AspNetUsers" because it does not exist or you do not have permissions.
And also if you could explain to me how the migration works for Identity tables?
回答1:
1) Took backup of all my work
2) Deleted Migration Folder
3) Using SQL Management Studio, From the Production Server, Deleted the Database
4) From Package Manager Console
Enable-Migrations -Force
Add-Migration init
Update-Database
You know what, all the tables are back on production database now :-) Thanks to Lin from How to re-create database for Entity Framework?
Hopefully this question/answer will help someone else like me
回答2:
Take a backup. Delete migration folder. Delete db. open package manager console > type Add-Migration "initail migration" > hit enter > type update-Database then you good to go.
回答3:
Instead of deleting the Database, you can delete only these tables:
__MigrationHistory,
AspNetRoles,
AspNetUserClaims,
AspNetUserLogins,
AspNetUserRoles
then delete the Migration folder and finaly from you PM console:
Enable-Migrations -Force
Add-Migration InitialCreate
Update-Database
来源:https://stackoverflow.com/questions/44298326/ef-code-first-project-doesnt-create-aspnetusers-aspnetroles-etc-tables-after-c