1
votes

How can I remove ASP.NET Identity tables from a database? Right now I have the following tables added to my database :

  • __MigrationHistory
  • AspNetRoles
  • AspNetUserClaims
  • AspNetUserLogins
  • AspNetUserRoles
  • AspNetUsers

I know that I could write something like the following :

DROP TABLE __MigrationHistory
DROP TABLE AspNetUserLogins
DROP TABLE AspNetUserRoles
DROP TABLE AspNetUserClaims
DROP TABLE AspNetRoles
DROP TABLE AspNetUsers

However I was wondering whether this is the right approach and if there is more elegant method of removing ASP.NET Identity tables and any other potential traces which I might have left out.

2
What's wrong with simply dropping the tables? - mason
Nothing is obviously wrong but I was asking whether this is the only method possible. - MHOOS
Any method is going to ultimately run these same drop commands. How did you create the tables? By running the commands directly against the server? Then the reverse is appropriate. I'm not familiar with setting up Identity, but did you call some sort of CreateTablesOnDatabase() function? If so, I imagine there's an equivalent DropTablesonDatabase() or you could see what the create function does to create the reverse. - mason
I use EF6 Code First approach and I derive my database from IdentityDbContext which automatically takes care of creating relevant tables plus the ones I explicitly specify. - MHOOS
I like your confidence but I have an advice for you as well. Don't be "over-confident". "Over confidence" is lethal. - MHOOS

2 Answers

1
votes

Just a note: __MigrationHistory is not part of Identity framework - it is table that stores information about DB state for EF-Migrations. If you would like to preserve the migration state and keep using the migrations, don't do anything to this table (unless you know what you are doing)

And I'll point out (seems like you have your answers already) that if you have created these tables by migration, you can roll back to "state-zero" by

update-database -target:0

This will run all your migrations back to the start and you'll be left with one table __MigrationHistory

0
votes

You have to remove following tables from the database.

DROP TABLE __EFMigrationsHistory
Drop Table AspNetRoleClaims
DROP TABLE AspNetUserLogins
DROP TABLE AspNetUserRoles
DROP TABLE AspNetUserClaims
Drop Table AspNetUserTokens
DROP TABLE AspNetRoles
DROP TABLE AspNetUsers

Also you need to drop Identity schema, if it's already exists orphan in your database.