I am trying to migrate the changes in models using following code
Add-Migration "InitialCreate"
Migration files are created after executing this command.
I tried to execute following command.
Update-Database
But, I am getting this error:
PM> Update-Database
Build started...
Build succeeded.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (24ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Account] (
[id] int NOT NULL IDENTITY,
[payable_amount] varchar(15) NULL,
[balance_amount] varchar(15) NULL,
[created_at] datetime NOT NULL,
[updated_at] datetime NOT NULL,
[deleted_at] datetime NULL,
CONSTRAINT [PK_Account] PRIMARY KEY ([id])
);
Failed executing DbCommand (24ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Account] (
[id] int NOT NULL IDENTITY,
[payable_amount] varchar(15) NULL,
[balance_amount] varchar(15) NULL,
[created_at] datetime NOT NULL,
[updated_at] datetime NOT NULL,
[deleted_at] datetime NULL,
CONSTRAINT [PK_Account] PRIMARY KEY ([id])
);
Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'Account' in the database.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
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 connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:1807d8da-31e6-4318-889f-77fff0e3ac25
Error Number:2714,State:6,Class:16
There is already an object named 'Account' in the database.
I have followed given link but it is not helpful.
There is already an object named in the database
FYI: I have undo all changes in data model and tried above process but still same error is occurring.