5

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 3

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Just as a comment, Enable-Migrations is now obsolete in EF Core. just start with Add-Migration
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.