gpt4 book ai didi

网络核心 : There is already an object named 'AspNetRoles' in the database

转载 作者:搜寻专家 更新时间:2023-10-30 22:26:41 24 4
gpt4 key购买 nike

我创建了一个新的 Asp.Net Core WebApi 项目并简单地添加了 IdentityDbContext,然后我在 Nuget Package Console 中编写了这些命令:

PM> Add-Migration Initial
To undo this action, use Remove-Migration.
PM> Update-Database
Applying migration '20180516150423_Initial'.
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [AspNetRoles] (
[Id] nvarchar(450) NOT NULL,
[ConcurrencyStamp] nvarchar(max) NULL,
[Name] nvarchar(256) NULL,
[NormalizedName] nvarchar(256) NULL,
CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
);
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [AspNetRoles] (
[Id] nvarchar(450) NOT NULL,
[ConcurrencyStamp] nvarchar(max) NULL,
[Name] nvarchar(256) NULL,
[NormalizedName] nvarchar(256) NULL,
CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
);
System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'AspNetRoles' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
ClientConnectionId:049426b7-c12c-421f-9236-c0212a40c216
Error Number:2714,State:6,Class:16
System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'AspNetRoles' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:049426b7-c12c-421f-9236-c0212a40c216
Error Number:2714,State:6,Class:16
There is already an object named 'AspNetRoles' in the database.
PM>

Google 云端硬盘项目:https://drive.google.com/open?id=16bYS7br2Ba7NcJYatPBDG2Q921o3MFcK

如果你尝试构建这个项目,你将对我有很大帮助。

最佳答案

There is already an object named 'AspNetRoles' in the database

AspNetRoles表已经存在。

您可以尝试两件事:

  1. 登录数据库服务器并运行drop database <your_db_name> .
  2. 更改连接字符串中的数据库名称。

现在 Add-Migration <MigrationClassName>命令将起作用。

关于网络核心 : There is already an object named 'AspNetRoles' in the database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50374731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com