c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -


i'm receiving error applicationdbcontext database when trying update entity framework. i've googled, tried fixes here on so, no avail. i'm deleting database each time make change, once deploy, not option.
here's error:

pm> update-database -context applicationdbcontext system.data.sqlclient.sqlexception: there object named 'aspnetroles' in database. @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action1 wrapcloseinaction) @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose) @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready) @ system.data.sqlclient.sqlcommand.runexecutenonquerytds(string methodname, boolean async, int32 timeout, boolean asyncwrite) @ system.data.sqlclient.sqlcommand.internalexecutenonquery(taskcompletionsource1 completion, boolean sendtopipe, int32 timeout, boolean asyncwrite, string methodname) @ system.data.sqlclient.sqlcommand.executenonquery() @ microsoft.entityframeworkcore.storage.internal.relationalcommand.execute(irelationalconnection connection, string executemethod, ireadonlydictionary2 parametervalues, boolean closeconnection) @ microsoft.entityframeworkcore.storage.internal.relationalcommand.executenonquery(irelationalconnection connection, ireadonlydictionary2 parametervalues) @ microsoft.entityframeworkcore.migrations.internal.migrationcommandexecutor.executenonquery(ienumerable`1 migrationcommands, irelationalconnection connection) @ microsoft.entityframeworkcore.migrations.internal.migrator.migrate(string targetmigration) @ microsoft.entityframeworkcore.design.internal.migrationsoperations.updatedatabase(string targetmigration, string contexttype) @ microsoft.entityframeworkcore.design.operationexecutor.updatedatabase.<>c__displayclass0_1.<.ctor>b__0() @ microsoft.entityframeworkcore.design.operationexecutor.operationbase.execute(action action) clientconnectionid:b2628a7e-7024-471e-9be2-2d0b25f3ad3c error number:2714,state:6,class:16 there object named 'aspnetroles' in database.

i have not used context.database.ensurecreated() anywhere in code.

the fastest solution is:

  • delete migration folder
  • delete database
  • enable-migrations
  • add initial migration
  • update-database

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -