Update-Database command is not working in ASP.Net Core / Entity Framework 6 because object in database already exists

asp.net-core c# database entity-framework-core sql


I was using the command line to update my database when I manually modified one of my tables.

I can't seem to update the database because of this. When I attempt to update, the following error appears:

 System.Data.SqlClient.SqlException: There is already an object named 'ClientsAndTestimonials' in the database.    at System.Data.SqlClient.SqlConnection.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, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean openConnection, Boolean closeConnection) 
    at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues, Boolean manageConnection) 
    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.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) 
    at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0() 
    at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
    at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
 Error Number:2714,State:6,Class:16
 There is already an object named 'ClientsAndTestimonials' in the database. 

For the last several days, I have been working to find a solution to this issue. Like John Salewski from the following link, the majority of fellow developers advise utilising Add-migration "Reset" -IgnoreChanges in some variant.

The message "A parameter cannot be discovered that matches parameter name 'IgnoreChanges'," nevertheless, keeps appearing.

Any advice would be much appreciated!

7/25/2019 6:54:32 PM

Accepted Answer

First off, that is EF Core and not EF 6. EF Core does not yet provide a -IgnoreChanges option (see here), but you can accomplish the same effect by commenting out all of the code in the Up() function and using the migration. By taking a snapshot of the current model state, future migrations will only take into account changes made after that.

As a result, you may need to withdraw your modifications, apply the baseline migration, put your changes back, then add a second migration if you just made any incremental model changes without having this first baseline.

4/28/2017 7:31:38 PM

Popular Answer

Instead, use Alter column. The method up(AddColumn )'s

        name: "IsActive",
        table: "Advertisements",
        nullable: false,
        defaultValue: true);


      public override void Up()
        AddColumn("dbo.Products", "Description", c => c.String(maxLength: 50));

Migration of asp.net

If you don't want the whole impact on the database, you may mark specific portions in the up function.

If your migration command is upset because they made them. Rebase migration and reset. How: Remove the migration-related material from Visual Studio and SQL,add-migration once moreupdate-database

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow