ASP.NET MVC and Web API – Fix – Already an object named AspNetRoles…

ASP.NET MVC and Web API
Fix / how-to

There is already an object named ‘AspNetRoles’ in the database.

 

Modify database in a security-aware project

Scenario: You’re attempting to modify the database in a security-aware project.

When attempting the Code First Migrations procedure, this error message appears:

There is already an object named ‘AspNetRoles’ in the database.

 

It is not a common error. Without a known log of tasks or actions, it is difficult to determine when the problem happened.

This fix will abandon the existing database (and its data!) and migrations, by creating a new database and “initial catalog”.

 

How to fix

Delete the migrations folder (and the code assets inside).

Open the Web.config source code file.

Locate the connection string.

Change these values. You can use whatever you want:

  • The name of the mdf file
  • The value of the “Initial Catalog” key-value pair

Then rebuild and run.

 

More info

As noted above, this action abandons the data that’s currently in the database. The old database is not deleted, just abandoned.

If necessary, you must reload the new database with initial and other data.

 

 

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Advertisements
%d bloggers like this: