title: EF Core There is already an object named 'AspNetRoles' in the database
body: <p>I am receiving <strong>There is already an object named <code>AspNetRoles</code> in the database.</strong> error while attempting to use <code>update-database</code> command in NuGet console.  </p>
  
  <p>Context:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;IdentityUser&gt;
  {
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options) { }
  
  
      public DbSet&lt;Customer&gt; Customers { get; set; }
  }
  </code></pre>
  
  <p>Startup:</p>
  
  <pre><code>public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                  b =&gt; b.MigrationsAssembly("DroneDeliveryWebApi")));
  
              // add identity
              var builder = services.AddIdentityCore&lt;AppUser&gt;(o =&gt;
              {
                  // configure identity options
                  o.Password.RequireDigit = false;
                  o.Password.RequireLowercase = false;
                  o.Password.RequireUppercase = false;
                  o.Password.RequireNonAlphanumeric = false;
                  o.Password.RequiredLength = 6;
              });
              builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), builder.Services);
              builder.AddEntityFrameworkStores&lt;ApplicationDbContext&gt;().AddDefaultTokenProviders();
  
              services.AddMvc();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseMvc();
          }
      }
  </code></pre>
  
  <p>appsetting.json:</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=DroneDeliverydb;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    "Logging": {
      "IncludeScopes": false,
      "Debug": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "Console": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "JwtIssuerOptions": {
        "Issuer": "DroneDeliveryWebApi",
        "Audience": "http://localhost:5000/"
      }
    }
  }
  </code></pre>
  
  <p>appsetting.Development.json:</p>
  
  <pre><code>{
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    },
  
    "JwtIssuerOptions": {
      "Issuer": "DroneDeliveryWebApi",
      "Audience": "http://localhost:5000/"
    }
  } 
  </code></pre>
  
  <p>Customer:</p>
  
  <pre><code>public class Customer
  {
      public int Id { get; set; }
      public string IdentityId { get; set; }
      public AppUser Identity { get; set; }
      public string Location { get; set; }
      public string Locale { get; set; }
      public string Gender { get; set; }
  }
  </code></pre>
  
  <p>Database:<br>
  <a href="https://i.stack.imgur.com/8tYzS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8tYzS.png" alt="enter image description here"></a>  </p>
  
  <p>Error:</p>
  
  <pre><code>PM&gt; update-database
  Applying migration '20190407181929_initial'.
  Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  CREATE TABLE [AspNetRoles] (
      [Id] nvarchar(450) NOT NULL,
      [ConcurrencyStamp] nvarchar(max) NULL,
      [Name] nvarchar(256) NULL,
      [NormalizedName] nvarchar(256) NULL,
      CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
  );
  fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
        Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
        CREATE TABLE [AspNetRoles] (
            [Id] nvarchar(450) NOT NULL,
            [ConcurrencyStamp] nvarchar(max) NULL,
            [Name] nvarchar(256) NULL,
            [NormalizedName] nvarchar(256) NULL,
            CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
        );
  System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'AspNetRoles' in the database.
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
  ClientConnectionId:e40d4c0a-f6df-498d-a92b-06c3711b5106
  Error Number:2714,State:6,Class:16
  System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'AspNetRoles' in the database.
     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
     at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
     at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
     at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
     at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
     at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
     at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
     at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.&lt;&gt;c__DisplayClass0_1.&lt;.ctor&gt;b__0()
     at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  ClientConnectionId:e40d4c0a-f6df-498d-a92b-06c3711b5106
  Error Number:2714,State:6,Class:16
  There is already an object named 'AspNetRoles' in the database.
  </code></pre>
  
  <p>You can ask me for any additional information</p>