EF Code First Project Doesn't Create AspNetUsers, AspNetRoles etc Tables after changing DB Connection

Viewed 3482

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?

3 Answers

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.

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
Related