I have been working on this for a while, and this is the third migration I am doing.
This is still an area I struggle with. However in this case I am trying to update without deleting my database as I want to try it. This is creating an error in dotnet method on cmd prompt as below:
System.Data.SqlClient.SqlException: There is already an object named 'ApplicationUser' 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 closeConnection) at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.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:c0190636-5eed-4a8e-aade-ba45a05ed942 Error Number:2714,State:6,Class:16 There is already an object named 'ApplicationUser' in the database.
I don't understand why it is fixated on Application User and where this is in relation to the migration code. From what I read of the migration code it is nothing to do with it.
namespace Eva804.Migrations { public partial class WaterTestType : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "WaterTestType", columns: table => new { WaterTestTypeID = table.Column<int>(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), WaterTstType = table.Column<string>(nullable: true) }, constraints: table => { table.PrimaryKey("PK_WaterTestType", x => x.WaterTestTypeID); }); migrationBuilder.CreateTable( name: "WaterTestTypeParameters", columns: table => new { WaterTestTypeParametersID = table.Column<int>(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), ChemicalParameterID = table.Column<int>(nullable: true), WaterTestTypeID = table.Column<int>(nullable: true) }, constraints: table => { table.PrimaryKey("PK_WaterTestTypeParameters", x => x.WaterTestTypeParametersID); table.ForeignKey( name: "FK_WaterTestTypeParameters_ChemicalParameters_ChemicalParameterID", column: x => x.ChemicalParameterID, principalTable: "ChemicalParameters", principalColumn: "ChemicalParameterID", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_WaterTestTypeParameters_WaterTestType_WaterTestTypeID", column: x => x.WaterTestTypeID, principalTable: "WaterTestType", principalColumn: "WaterTestTypeID", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_WaterTestTypeParameters_ChemicalParameterID", table: "WaterTestTypeParameters", column: "ChemicalParameterID"); migrationBuilder.CreateIndex( name: "IX_WaterTestTypeParameters_WaterTestTypeID", table: "WaterTestTypeParameters", column: "WaterTestTypeID"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "WaterTestTypeParameters"); migrationBuilder.DropTable( name: "WaterTestType"); } }
The other confusing point is after reading on line various stackoverflow posts and so on they are referring to the migration table in my SQL server. When I open this table I find it contains no data which is very confusing as I have run several migrations on this database.
Any guidance please?