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, action
1 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(taskcompletionsource
1 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, ireadonlydictionary
2 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
Post a Comment