c# - Entity Framework Code Migrations: Exception has been thrown by the target of an invocation -


i'm using code first entity framework 5 in mvc project. today making changes domain model , updated rest of application work these new changes. naturally, when changes domain model made, you'll need update database. we're using code migrations (manual migration, is). when tried add new migration through package console, i'm getting following exception:

exception has been thrown target of invocation.

i've tried adding startup project command, didn't work either. of projects build no compiler errors either.

edit: also, happens no matter do: update-database or update-database target migration. seem give me same exception.

this callstack:

pm> add-migration mymigrationname system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.data.entity.migrations.infrastructure.automaticmigrationsdisabledexception: unable update database match current model because there pending changes , automatic migration disabled. either write pending model changes code-based migration or enable automatic migration. set dbmigrationsconfiguration.automaticmigrationsenabled true enable automatic migration.    @ system.data.entity.migrations.dbmigrator.upgrade(ienumerable`1 pendingmigrations, string targetmigrationid, string lastmigrationid)    @ system.data.entity.migrations.dbmigrator.update(string targetmigration)    @ system.data.entity.migratedatabasetolatestversion`2.initializedatabase(tcontext context)    @ system.data.entity.database.<>c__displayclass2`1.<setinitializerinternal>b__0(dbcontext c)    @ system.data.entity.internal.internalcontext.<>c__displayclass8.<performdatabaseinitialization>b__6()    @ system.data.entity.internal.internalcontext.performinitializationaction(action action)    @ system.data.entity.internal.internalcontext.performdatabaseinitialization()    @ system.data.entity.internal.lazyinternalcontext.<initializedatabase>b__4(internalcontext c)    @ system.data.entity.internal.retryaction`1.performaction(tinput input)    @ system.data.entity.internal.lazyinternalcontext.initializedatabaseaction(action`1 action)    @ system.data.entity.internal.lazyinternalcontext.initializedatabase()    @ system.data.entity.internal.internalcontext.forceospaceloadingforknownentitytypes()    @ system.data.entity.dbcontext.system.data.entity.infrastructure.iobjectcontextadapter.get_objectcontext()    @ entityframework.audit.auditlogger..ctor(dbcontext dbcontext, auditconfiguration configuration)    @ entityframework.extensions.auditextensions.beginaudit(dbcontext dbcontext, auditconfiguration configuration)    @ project.dataaccesslogic.mycontext..ctor() in c:..\mycontext.cs:line 125    --- end of inner exception stack trace ---    @ system.runtimetypehandle.createinstance(runtimetype type, boolean publiconly, boolean nocheck, boolean& canbecached, runtimemethodhandleinternal& ctor, boolean& bneedsecuritycheck)    @ system.runtimetype.createinstanceslow(boolean publiconly, boolean skipcheckthis, boolean fillcache, stackcrawlmark& stackmark)    @ system.runtimetype.createinstancedefaultctor(boolean publiconly, boolean skipcheckthis, boolean fillcache, stackcrawlmark& stackmark)    @ system.activator.createinstance(type type, boolean nonpublic)    @ system.activator.createinstance(type type)    @ system.data.entity.infrastructure.dbcontextinfo.<createactivator>b__0()    @ system.data.entity.infrastructure.dbcontextinfo..ctor(type contexttype, dbproviderinfo modelproviderinfo, appconfig config, dbconnectioninfo connectioninfo)    @ system.data.entity.infrastructure.dbcontextinfo..ctor(type contexttype)    @ system.data.entity.migrations.dbmigrator..ctor(dbmigrationsconfiguration configuration, dbcontext userscontext)    @ system.data.entity.migrations.dbmigrator..ctor(dbmigrationsconfiguration configuration)    @ system.data.entity.migrations.design.toolingfacade.baserunner.getmigrator()    @ system.data.entity.migrations.design.toolingfacade.getpendingmigrationsrunner.runcore()    @ system.data.entity.migrations.design.toolingfacade.baserunner.run() exception has been thrown target of invocation. 

i'm not sure should start look.

i error when don't set connection strings properly.

make sure following correct in web.config:

  1. data source
  2. initial catalog
  3. user id
  4. password

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -