title: EntityFrameworkCore for Sqlite not creating __EFMigrationHistory table
body: <p>Before I explain my issue, I have some experience with entity framework 5 and 6 code first migrations, running <code>add-migration</code>/<code>update-database</code> and a few more specific commands from the Package Manager console. All of the migration history was handled out of the box in the <code>__MigrationHistory</code> table.</p>
  
  <p>I am now writing a UWP app and using <code>EntityFrameworkCore</code> sqlite. The app is set up to scaffold new migrations and does so correctly.</p>
  
  <p>When applying migrations the app needs to automatically deduce, on install and first startup, if the database exists, and the current database migration version. It can then apply the relevant migration procedures, including creating the database if required.</p>
  
  <p>Currently, I attempt to perform the migrations in my DbContext on startup:</p>
  
  <pre><code>public class MyContext : DbContext
  {        
      public DbSet&lt;SomeEntity&gt; MyEntities { get; set; }
  
      static MyContext()
      {
          using(var db = new MyContext())
          {
              db.Database.Migrate();
          }
      }
  </code></pre>
  
  <p>This works perfectly for a new app on first startup. On second startup however, or after the addition of a new migration, the Migrate() method fails as the tables it is attempting to create already exist.</p>
  
  <blockquote>
    <blockquote>
      <p>SQLite Error 1: 'table \"MyEntities\" already exists'</p>
    </blockquote>
  </blockquote>
  
  <p>This error comes from rerunning the migration that has been previously applied. The database itself needs to be aware of it's migration history as was previously handled with <code>__EFMigrationHistory</code>. Currently this table is not being created for me.</p>
  
  <p>I am suspecting that I need to manually build a solution to this, maybe creating my own __MigrationHistory table and keeping it up to date, as per this post <a href="https://github.com/aspnet/EntityFramework/issues/6273#issuecomment-239919733" rel="nofollow noreferrer">here</a></p>
  
  <p>I wondered what solutions people have used for this issue, or if there is anything out of the box that I'm being silly and missing.</p>
  
  <p>Let me know if more detail needed.</p>