title: MVC 5: Database table not being generated when program is run
body: <p>I have MVC 5 application.
  This is the Default <code>ApplicationUser</code> and <code>ApplicationDbContext</code> class which i have edited as per my need</p>
  
  <pre><code>public class ApplicationUser : IdentityUser
  {
      [Key]
      public Guid UserId { get; set; }
      [Required]
      public override string UserName { get; set; }
      [Required, DataType(DataType.Password)]
      public string Password { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
  
      public string Email { get; set; }
      public Boolean IsApproved { get; set; }
  
      public string Company { get; set; }
      [DataType(DataType.MultilineText)]
      public string Comment { get; set; }
  
      public DateTime DateTimeRegistered { get; set; }
      public DateTime? LastLoginDate { get; set; }
      public DateTime? LastActivityDate { get; set; }
  
      public int PasswordFailureSinceLastSuccess { get; set; }
      public DateTime? LastPasswordFailureDate { get; set; }
      public string PasswordVerificationToken { get; set; }
      public DateTime? PasswordVerificationTokenExpirationDate { get; set; }
      public string ConfirmationToken { get; set; }
  
      public List&lt;AddressBook&gt; AddressBook { get; set; }
      public IEnumerable&lt;Appointment&gt; Appointments { get; set; }
  
      public Role Role { get; set; }
  
      public License License { get; set; }
  }
  
  public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext():base("DefaultConnection")
      {
      }
      protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
          modelBuilder.Entity&lt;IdentityUser&gt;().ToTable("Users");
          modelBuilder.Entity&lt;ApplicationUser&gt;().ToTable("Users");
      }
      public DbSet&lt;License&gt; Licenses { get; set; }
      public override IDbSet&lt;IdentityRole&gt; Roles { get; set; }
  
      public DbSet&lt;AddressBook&gt; AddressBooks { get; set; }
      public DbSet&lt;AddressBookPerson&gt; AddressBookPersons { get; set; }
  
      public DbSet&lt;Appointment&gt; Appointments { get; set; }
  
      public DbSet&lt;Attendee&gt; Attendees { get; set; }
  
      public DbSet&lt;Response&gt; Responses { get; set; } 
  
  }
  </code></pre>
  
  <p>Here is my <code>webconfig</code> file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=301880
    --&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DatePicker;Data Source=(local)" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;add key="enableSimpleMembership" value="false" /&gt;&lt;add key="DatabaseInitializerForType DataContext, DatePicker" value="DataContextInitializer, DatePicker" /&gt;&lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;authentication mode="None" /&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthenticationModule" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
        &lt;parameter value="Data Source=(local); User ID=crm7; Password=crm7myd; MultipleActiveResultSets=True" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This is the default <code>Accountcontroller</code> class nothing is changed</p>
  
  <pre><code>public class AccountController : Controller
  {
      public AccountController()
          : this(new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(new ApplicationDbContext())))
      {
      }
  
      public AccountController(UserManager&lt;ApplicationUser&gt; userManager)
      {
          UserManager = userManager;
      }
  
      public UserManager&lt;ApplicationUser&gt; UserManager { get; private set; }
  
  
  
       // GET: /Account/Register
       [AllowAnonymous]
       public ActionResult Register()
       {
           return View();
       }
  
       //
      // POST: /Account/Register
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
      {
          if (ModelState.IsValid)
          {
              var user = new ApplicationUser() { UserName = model.UserName };
              var result = await UserManager.CreateAsync(user, model.Password);
              if (result.Succeeded)
              {
                  await SignInAsync(user, isPersistent: false);
                  return RedirectToAction("Index", "Home");
              }
              else
              {
                  AddErrors(result);
              }
          }
  
         // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>When I run the application and try to register a user i get error on this part of Post method</p>
  
  <pre><code>var result = await UserManager.CreateAsync(user, model.Password);
  </code></pre>
  
  <p>Stacktrace in browser says </p>
  
  <pre><code>[SqlException (0x80131904): Login failed for user ''.]
     System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352431
     System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
     System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady) +1691
     System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69
     System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30
     System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +317
     System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +891
     System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
     System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +518
     System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
     System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
     System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
     System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
     System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection) +1057
     System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection) +78
     System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&amp; connection) +196
     System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
     System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
     System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
     System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
     System.Data.SqlClient.SqlConnection.Open() +96
     System.Data.Entity.SqlServer.&lt;&gt;c__DisplayClass2f.&lt;UsingConnection&gt;b__2d() +136
     System.Data.Entity.SqlServer.&lt;&gt;c__DisplayClass1.&lt;Execute&gt;b__0() +34
     System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +251
     System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +196
     System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) +345
     System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +219
  
  [InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.]
     System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +406
     System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +350
     System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +132
  
  [ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
     System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +327
     System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +67
  
  [ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.]
     System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +228
  </code></pre>
  
  <p>what am i doing wrong?
  I was expecting database tables to be created but it is not. Is it because of my connection string problem?</p>
  
  <p><strong>Edit 1:</strong>
  I commented following part from webconfig file </p>
  
  <pre><code>&lt;!--&lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DatePicker;Data Source=(local)" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;--&gt;
  </code></pre>
  
  <p>and now the error in browser says</p>
  
  <pre><code>Could not load type 'DataContext' from assembly 'DatePicker'.
  </code></pre>
  
  <p>error is in same line as before</p>
  
  <p>Stacktrace</p>
  
  <pre><code>[TypeLoadException: Could not load type 'DataContext' from assembly 'DatePicker'.]
     System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
     System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
     System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&amp; stackMark) +39
     System.Type.GetType(String typeName, Boolean throwOnError) +34
     System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(Type requiredContextType, String contextTypeName, String initializerTypeName, Boolean isDisabled, Func`1 initializerArgs, Func`3 exceptionMessage) +76
  
  [InvalidOperationException: Failed to set database initializer of type 'DataContextInitializer, DatePicker' for DbContext type 'DataContext, DatePicker' specified in the application configuration. Entries should be of the form 'key="DatabaseInitializerForType MyNamespace.MyDbContextClass, MyAssembly" value="MyNamespace.MyInitializerClass, MyAssembly"' or 'key="DatabaseInitializerForType MyNamespace.MyDbContextClass, MyAssembly" value="Disabled"'. Also verify that 'DatabaseInitializerArgumentForType' entries are present for every parameter of the database initializer constructor. See inner exception for details. Consider using the &lt;entityFramework&gt; configuration section to set the database initializer (http://go.microsoft.com/fwlink/?LinkID=237468).]
     System.Data.Entity.Internal.InitializerConfig.TryGetInitializer(Type requiredContextType, String contextTypeName, String initializerTypeName, Boolean isDisabled, Func`1 initializerArgs, Func`3 exceptionMessage) +366
     System.Data.Entity.Internal.InitializerConfig.TryGetInitializerFromLegacyConfig(Type contextType) +908
  </code></pre>