title: Invalid object name 'dbo.__MigrationHistory' using Database.Create; EF6.02 when connection string is passed in
body: <p>I experience an error when trying to create a database using the following code.
  Note the problem does not happen if the connection string is not passed in.
  Also the problem happens when I run the program in the IDE. It does not happen if I run the program .exe or if I run the unit tests within the IDE.</p>
  
  <p>However if the database is created by running the unit tests or by running the .EXE then the <code>__MigrationHistory</code> table is created in the main tables section, not the system tables.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public Context(string connString, bool AddInitialRecords )
      : base(connString ?? "MyContextName")
  {
      this.CheckDatabase(AddInitialRecords);
  }
  
  public void CheckDatabase(bool AddInitialRecords)
  {
      if (this.Database.Exists())
      {
           // upgrade stuff
      }
      else
      {
         Database.Create();  // error occurs here
          // seeding stuff 
      }
  }
  </code></pre>
  
  <p>I don't get the problem if I just use something like </p>
  
  <pre class="lang-cs prettyprint-override"><code>var db1 = new Context();
  db1.Database.CreateIfNotExists();
  </code></pre>
  
  <p>I have found some documentation <a href="http://entityframework.codeplex.com/workitem/595" rel="noreferrer">here</a>  but it confuses me.  I am installing from a "stable build" surely I aren't experiencing something from 2012? What could I be doing wrong with PM?</p>
  
  <p>The error message for the problem is....</p>
  
  <blockquote>
    <p>System.Data.Entity.Core.EntityCommandExecutionException occurred<br>
    HResult=-2146232004   Message=An error occurred while executing the
    command definition. See the inner exception for details.<br>
    Source=EntityFramework   StackTrace:
           at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior behavior)   InnerException:
    System.Data.SqlClient.SqlException
           HResult=-2146232060
           Message=Invalid object name 'dbo.__MigrationHistory'.
           Source=.Net SqlClient Data Provider
           ErrorCode=-2146232060
           Class=16
           LineNumber=1
           Number=208
           Procedure=""
           Server=.\SQLEXPRESS
           State=1
           StackTrace:
                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.SqlDataReader.TryConsumeMetaData()
                at System.Data.SqlClient.SqlDataReader.get_MetaData()
                at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
    RunBehavior runBehavior, String resetOptionsString)
                at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
    async, Int32 timeout, Task&amp; task, Boolean asyncWrite)
                at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task,
    Boolean asyncWrite)
                at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method)
                at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    behavior, String method)
                at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
    behavior)
                at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.&lt;>c__DisplayClassb.b__8()
                at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,TResult](Func`1
    operation, TInterceptionContext interceptionContext, Action`1
    executing, Action`1 executed)
                at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand
    command, DbCommandInterceptionContext interceptionContext)
                at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior
    behavior)
                at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand
    entityCommand, CommandBehavior behavior)
           InnerException:</p>
  </blockquote>