title: Entity Framework Core is not creating tables in my databases
body: <p>I've tried deleting and creating a new database, deleting and creating new migrations, and can't get anything to work. </p>
  
  <p>First, I created a new database, then put the connection string in appsettings, and tried to run "update-database". All I got was this:</p>
  
  <pre><code>Executed DbCommand (178ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT OBJECT_ID(N'__EFMigrationsHistory');
  Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT OBJECT_ID(N'__EFMigrationsHistory');
  Executed DbCommand (8ms) [Parameters=[], CommandType='Text',    CommandTimeout='30']
  SELECT [MigrationId], [ProductVersion]
  FROM [__EFMigrationsHistory]
  ORDER BY [MigrationId];
  Done.
  </code></pre>
  
  <p>And nothing was created. So, I deleted everything and started from scratch, then I got this:</p>
  
  <pre><code>Executed DbCommand (141ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT OBJECT_ID(N'__EFMigrationsHistory');
  Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT OBJECT_ID(N'__EFMigrationsHistory');
  Executed DbCommand (20ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT [MigrationId], [ProductVersion]
  FROM [__EFMigrationsHistory]
  ORDER BY [MigrationId];
  Applying migration '20181220145036_test'.
  Executed DbCommand (49ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  CREATE TABLE [CartItems] (
      [ID] int NOT NULL IDENTITY,
      [cartID] nvarchar(max),
      [itempicture] nvarchar(max),
      [name] nvarchar(max),
      [price] int NOT NULL,
      [productID] int NOT NULL,
      CONSTRAINT [PK_CartItems] PRIMARY KEY ([ID])
  );
  System.Data.SqlClient.SqlException: There is already an object named 'CartItems' in the database.
     at System.Data.SqlClient.SqlConnection.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, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean closeConnection)
     at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.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:2170e7ba-871f-416a-88c9-bfb2bf586d3d
  Error Number:2714,State:6,Class:16
  There is already an object named 'CartItems' in the database.
  </code></pre>
  
  <p>And I know this is wrong because it's a brand new, empty database. Some of my code:</p>
  
  <p>ApplicationDbContext:</p>
  
  <pre><code>public class ApplicationDbContextFactory : IDbContextFactory&lt;ApplicationDbContext&gt;
  {
      public ApplicationDbContext Create(DbContextFactoryOptions options)
      {
          var optionsBuilder = new DbContextOptionsBuilder&lt;ApplicationDbContext&gt;();
  
          return new ApplicationDbContext(optionsBuilder.Options);
      }
  }
  
  public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options)
      {
      }
  
      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
          if (!optionsBuilder.IsConfigured)
          {
              IConfigurationRoot configuration = new ConfigurationBuilder()
                   .SetBasePath(Directory.GetCurrentDirectory())
                   .AddJsonFile("appsettings.json")
                   .Build();
  
              var connectionString = configuration.GetConnectionString("DefaultConnection");
  
              optionsBuilder.UseSqlServer(connectionString);
          }
      }
  
      //protected override void OnModelCreating(ModelBuilder builder)
      //{
      //    base.OnModelCreating(builder);
      //    // Customize the ASP.NET Identity model and override the defaults if needed.
      //    // For example, you can rename the ASP.NET Identity table names and more.
      //    // Add your customizations after calling base.OnModelCreating(builder);
      //}
  
      public DbSet&lt;Product&gt; Products { get; set; }
      public DbSet&lt;Order&gt; Orders { get; set; }
      public DbSet&lt;CartItems&gt; CartItems { get; set; }
      public DbSet&lt;OrderDetails&gt; OrderDetails { get; set; }
  }
  </code></pre>
  
  <p>CartItems:</p>
  
  <pre><code>public class CartItems
  {
      public int ID { get; set; }
      public string cartID { get; set; }
      public string name { get; set; }
      public int price { get; set; }
      public string itempicture { get; set; }
      public int productID { get; set; }
  }
  </code></pre>
  
  <p>I've been able to create tables with this same code and application in the past. I also use EFCore the same way in other projects currently without any issues. So, I'd really appreciate some help in getting this back working again. I'd like to know what to do about this in the future. </p>
  
  <p><strong>Edit:</strong> connection string: </p>
  
  <pre><code>"DefaultConnection": "Data Source=CHRISTOPHER09E8;Initial Catalog=LNCTest;Integrated Security=True"
  </code></pre>
  
  <p><strong>EDIT2:</strong> Migration:</p>
  
  <pre><code>namespace LNCLibrary.Migrations
  {
      public partial class Initialv1 : Migration
      {
          protected override void Up(MigrationBuilder migrationBuilder)
          {
              migrationBuilder.CreateTable(
                  name: "CartItems",
                  columns: table =&gt; new
                  {
                      ID = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      cartID = table.Column&lt;string&gt;(nullable: true),
                      itempicture = table.Column&lt;string&gt;(nullable: true),
                      name = table.Column&lt;string&gt;(nullable: true),
                      price = table.Column&lt;int&gt;(nullable: false),
                      productID = table.Column&lt;int&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_CartItems", x =&gt; x.ID);
                  });
  
              migrationBuilder.CreateTable(
                  name: "Products",
                  columns: table =&gt; new
                  {
                      ID = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      Category = table.Column&lt;int&gt;(nullable: false),
                      DateCreated = table.Column&lt;DateTime&gt;(nullable: false),
                      GenderOption = table.Column&lt;int&gt;(nullable: false),
                      Price = table.Column&lt;int&gt;(nullable: false),
                      ProductDescription = table.Column&lt;string&gt;(nullable: true),
                      ProductName = table.Column&lt;string&gt;(nullable: true),
                      ProfilePicture = table.Column&lt;string&gt;(nullable: true),
                      Quantity = table.Column&lt;int&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_Products", x =&gt; x.ID);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetUsers",
                  columns: table =&gt; new
                  {
                      Id = table.Column&lt;string&gt;(nullable: false),
                      AccessFailedCount = table.Column&lt;int&gt;(nullable: false),
                      Address = table.Column&lt;string&gt;(nullable: true),
                      CheckoutComments = table.Column&lt;string&gt;(nullable: true),
                      City = table.Column&lt;string&gt;(nullable: true),
                      ConcurrencyStamp = table.Column&lt;string&gt;(nullable: true),
                      Email = table.Column&lt;string&gt;(maxLength: 256, nullable: true),
                      EmailConfirmed = table.Column&lt;bool&gt;(nullable: false),
                      FirstName = table.Column&lt;string&gt;(nullable: true),
                      LastName = table.Column&lt;string&gt;(nullable: true),
                      LockoutEnabled = table.Column&lt;bool&gt;(nullable: false),
                      LockoutEnd = table.Column&lt;DateTimeOffset&gt;(nullable: true),
                      NormalizedEmail = table.Column&lt;string&gt;(maxLength: 256, nullable: true),
                      NormalizedUserName = table.Column&lt;string&gt;(maxLength: 256, nullable: true),
                      PasswordHash = table.Column&lt;string&gt;(nullable: true),
                      PhoneNumber = table.Column&lt;string&gt;(nullable: true),
                      PhoneNumberConfirmed = table.Column&lt;bool&gt;(nullable: false),
                      SecurityStamp = table.Column&lt;string&gt;(nullable: true),
                      State = table.Column&lt;int&gt;(nullable: false),
                      TwoFactorEnabled = table.Column&lt;bool&gt;(nullable: false),
                      UserName = table.Column&lt;string&gt;(maxLength: 256, nullable: true),
                      ZipCode = table.Column&lt;int&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetUsers", x =&gt; x.Id);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetRoles",
                  columns: table =&gt; new
                  {
                      Id = table.Column&lt;string&gt;(nullable: false),
                      ConcurrencyStamp = table.Column&lt;string&gt;(nullable: true),
                      Name = table.Column&lt;string&gt;(maxLength: 256, nullable: true),
                      NormalizedName = table.Column&lt;string&gt;(maxLength: 256, nullable: true)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetRoles", x =&gt; x.Id);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetUserTokens",
                  columns: table =&gt; new
                  {
                      UserId = table.Column&lt;string&gt;(nullable: false),
                      LoginProvider = table.Column&lt;string&gt;(nullable: false),
                      Name = table.Column&lt;string&gt;(nullable: false),
                      Value = table.Column&lt;string&gt;(nullable: true)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetUserTokens", x =&gt; new { x.UserId, x.LoginProvider, x.Name });
                  });
  
              migrationBuilder.CreateTable(
                  name: "Size",
                  columns: table =&gt; new
                  {
                      ID = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      ProductID = table.Column&lt;int&gt;(nullable: true),
                      ThisSize = table.Column&lt;int&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_Size", x =&gt; x.ID);
                      table.ForeignKey(
                          name: "FK_Size_Products_ProductID",
                          column: x =&gt; x.ProductID,
                          principalTable: "Products",
                          principalColumn: "ID",
                          onDelete: ReferentialAction.Restrict);
                  });
  
              migrationBuilder.CreateTable(
                  name: "Orders",
                  columns: table =&gt; new
                  {
                      ID = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      Address = table.Column&lt;string&gt;(nullable: true),
                      CartID = table.Column&lt;string&gt;(nullable: true),
                      CheckoutComments = table.Column&lt;string&gt;(nullable: true),
                      City = table.Column&lt;string&gt;(nullable: true),
                      ConfirmationNumber = table.Column&lt;string&gt;(nullable: true),
                      DateOfPurchase = table.Column&lt;DateTime&gt;(nullable: false),
                      Email = table.Column&lt;string&gt;(nullable: true),
                      FinalPrice = table.Column&lt;float&gt;(nullable: false),
                      FirstName = table.Column&lt;string&gt;(nullable: true),
                      LastName = table.Column&lt;string&gt;(nullable: true),
                      PaymentMethod = table.Column&lt;int&gt;(nullable: false),
                      RegularCustomerId = table.Column&lt;string&gt;(nullable: true),
                      State = table.Column&lt;int&gt;(nullable: false),
                      Status = table.Column&lt;int&gt;(nullable: false),
                      ZipCode = table.Column&lt;int&gt;(nullable: false),
                      isGuest = table.Column&lt;bool&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_Orders", x =&gt; x.ID);
                      table.ForeignKey(
                          name: "FK_Orders_AspNetUsers_RegularCustomerId",
                          column: x =&gt; x.RegularCustomerId,
                          principalTable: "AspNetUsers",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Restrict);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetUserClaims",
                  columns: table =&gt; new
                  {
                      Id = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      ClaimType = table.Column&lt;string&gt;(nullable: true),
                      ClaimValue = table.Column&lt;string&gt;(nullable: true),
                      UserId = table.Column&lt;string&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetUserClaims", x =&gt; x.Id);
                      table.ForeignKey(
                          name: "FK_AspNetUserClaims_AspNetUsers_UserId",
                          column: x =&gt; x.UserId,
                          principalTable: "AspNetUsers",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Cascade);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetUserLogins",
                  columns: table =&gt; new
                  {
                      LoginProvider = table.Column&lt;string&gt;(nullable: false),
                      ProviderKey = table.Column&lt;string&gt;(nullable: false),
                      ProviderDisplayName = table.Column&lt;string&gt;(nullable: true),
                      UserId = table.Column&lt;string&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetUserLogins", x =&gt; new { x.LoginProvider, x.ProviderKey });
                      table.ForeignKey(
                          name: "FK_AspNetUserLogins_AspNetUsers_UserId",
                          column: x =&gt; x.UserId,
                          principalTable: "AspNetUsers",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Cascade);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetRoleClaims",
                  columns: table =&gt; new
                  {
                      Id = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      ClaimType = table.Column&lt;string&gt;(nullable: true),
                      ClaimValue = table.Column&lt;string&gt;(nullable: true),
                      RoleId = table.Column&lt;string&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetRoleClaims", x =&gt; x.Id);
                      table.ForeignKey(
                          name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
                          column: x =&gt; x.RoleId,
                          principalTable: "AspNetRoles",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Cascade);
                  });
  
              migrationBuilder.CreateTable(
                  name: "AspNetUserRoles",
                  columns: table =&gt; new
                  {
                      UserId = table.Column&lt;string&gt;(nullable: false),
                      RoleId = table.Column&lt;string&gt;(nullable: false)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_AspNetUserRoles", x =&gt; new { x.UserId, x.RoleId });
                      table.ForeignKey(
                          name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
                          column: x =&gt; x.RoleId,
                          principalTable: "AspNetRoles",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Cascade);
                      table.ForeignKey(
                          name: "FK_AspNetUserRoles_AspNetUsers_UserId",
                          column: x =&gt; x.UserId,
                          principalTable: "AspNetUsers",
                          principalColumn: "Id",
                          onDelete: ReferentialAction.Cascade);
                  });
  
              migrationBuilder.CreateTable(
                  name: "OrderDetails",
                  columns: table =&gt; new
                  {
                      ID = table.Column&lt;int&gt;(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                      CartID = table.Column&lt;string&gt;(nullable: true),
                      Name = table.Column&lt;string&gt;(nullable: true),
                      OrderID = table.Column&lt;int&gt;(nullable: false),
                      price = table.Column&lt;int&gt;(nullable: false),
                      productpicture = table.Column&lt;string&gt;(nullable: true)
                  },
                  constraints: table =&gt;
                  {
                      table.PrimaryKey("PK_OrderDetails", x =&gt; x.ID);
                      table.ForeignKey(
                          name: "FK_OrderDetails_Orders_OrderID",
                          column: x =&gt; x.OrderID,
                          principalTable: "Orders",
                          principalColumn: "ID",
                          onDelete: ReferentialAction.Cascade);
                  });
  
              migrationBuilder.CreateIndex(
                  name: "IX_Orders_RegularCustomerId",
                  table: "Orders",
                  column: "RegularCustomerId");
  
              migrationBuilder.CreateIndex(
                  name: "IX_OrderDetails_OrderID",
                  table: "OrderDetails",
                  column: "OrderID");
  
              migrationBuilder.CreateIndex(
                  name: "IX_Size_ProductID",
                  table: "Size",
                  column: "ProductID");
  
              migrationBuilder.CreateIndex(
                  name: "EmailIndex",
                  table: "AspNetUsers",
                  column: "NormalizedEmail");
  
              migrationBuilder.CreateIndex(
                  name: "UserNameIndex",
                  table: "AspNetUsers",
                  column: "NormalizedUserName",
                  unique: true);
  
              migrationBuilder.CreateIndex(
                  name: "RoleNameIndex",
                  table: "AspNetRoles",
                  column: "NormalizedName",
                  unique: true);
  
              migrationBuilder.CreateIndex(
                  name: "IX_AspNetRoleClaims_RoleId",
                  table: "AspNetRoleClaims",
                  column: "RoleId");
  
              migrationBuilder.CreateIndex(
                  name: "IX_AspNetUserClaims_UserId",
                  table: "AspNetUserClaims",
                  column: "UserId");
  
              migrationBuilder.CreateIndex(
                  name: "IX_AspNetUserLogins_UserId",
                  table: "AspNetUserLogins",
                  column: "UserId");
  
              migrationBuilder.CreateIndex(
                  name: "IX_AspNetUserRoles_RoleId",
                  table: "AspNetUserRoles",
                  column: "RoleId");
          }
  
          protected override void Down(MigrationBuilder migrationBuilder)
          {
              migrationBuilder.DropTable(
                  name: "CartItems");
  
              migrationBuilder.DropTable(
                  name: "OrderDetails");
  
              migrationBuilder.DropTable(
                  name: "Size");
  
              migrationBuilder.DropTable(
                  name: "AspNetRoleClaims");
  
              migrationBuilder.DropTable(
                  name: "AspNetUserClaims");
  
              migrationBuilder.DropTable(
                  name: "AspNetUserLogins");
  
              migrationBuilder.DropTable(
                  name: "AspNetUserRoles");
  
              migrationBuilder.DropTable(
                  name: "AspNetUserTokens");
  
              migrationBuilder.DropTable(
                  name: "Orders");
  
              migrationBuilder.DropTable(
                  name: "Products");
  
              migrationBuilder.DropTable(
                  name: "AspNetRoles");
  
              migrationBuilder.DropTable(
                  name: "AspNetUsers");
          }
      }
  }
  </code></pre>