title: Entity Framework Code Migrations: Exception has been thrown by the target of an invocation
body: <p>I'm using Code first Entity Framework 5 in my MVC project. Today I was making some changes to my domain model and updated the rest of the application to work with these new changes. Naturally, when changes to the domain model is made, you'll need to update the database. We're using code migrations to do that (manual migration, that is). However when I tried to add a new migration through the package console, i'm getting the following exception:</p>
  
  <blockquote>
    <p>Exception has been thrown by the target of an invocation.</p>
  </blockquote>
  
  <p>I've tried adding the startup project to the command, which didn't work either. All of my projects build so no compiler errors either. </p>
  
  <p>EDIT: Also, this happens no matter what I do: update-database or update-database with a target migration. All seem to give me the same exception.</p>
  
  <p>This is the callstack:</p>
  
  <pre><code>PM&gt; add-migration MyMigrationName
  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
     at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
     at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
     at System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context)
     at System.Data.Entity.Database.&lt;&gt;c__DisplayClass2`1.&lt;SetInitializerInternal&gt;b__0(DbContext c)
     at System.Data.Entity.Internal.InternalContext.&lt;&gt;c__DisplayClass8.&lt;PerformDatabaseInitialization&gt;b__6()
     at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
     at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
     at System.Data.Entity.Internal.LazyInternalContext.&lt;InitializeDatabase&gt;b__4(InternalContext c)
     at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
     at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
     at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
     at EntityFramework.Audit.AuditLogger..ctor(DbContext dbContext, AuditConfiguration configuration)
     at EntityFramework.Extensions.AuditExtensions.BeginAudit(DbContext dbContext, AuditConfiguration configuration)
     at Project.DataAccessLogic.MyContext..ctor() in c:..\MyContext.cs:line 125
     --- End of inner exception stack trace ---
     at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     at System.Activator.CreateInstance(Type type, Boolean nonPublic)
     at System.Activator.CreateInstance(Type type)
     at System.Data.Entity.Infrastructure.DbContextInfo.&lt;CreateActivator&gt;b__0()
     at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
     at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType)
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
     at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
     at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
     at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
  Exception has been thrown by the target of an invocation.
  </code></pre>
  
  <p>I'm not sure where I should start to look.</p>