0
murat.yuceer created
Hi,
I have a table that named Organization which inherited from OrganizationUnit that uses by ABP.
public sealed class Organization : OrganizationUnit
{
//some codes..
}
And i had overwrite the table name by adding following configuration below :
namespace Kuys.EntityFrameworkCore.EntityFrameworkCore.Configurations.Organization.Organizations
{
public class OrganizationUnitConfiguration : IEntityTypeConfiguration<OrganizationUnit>
{
public void Configure(EntityTypeBuilder<OrganizationUnit> builder)
{
builder.ToTable("Organizations", SchemaNames.Organization);
}
}
}
However, since when i upgrade my abp version to latest (core 5), i'm getting the following error messages on update-database operation.
System.InvalidOperationException: To change the IDENTITY property of a column, the column needs to be dropped and recreated.
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.<>c.<.cctor>b__83_4(MigrationsSqlGenerator g, MigrationOperation o, IModel m, MigrationCommandListBuilder b)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model, MigrationsSqlGenerationOptions options)
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(IReadOnlyList`1 operations, IModel model, MigrationsSqlGenerationOptions options)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
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)
To change the IDENTITY property of a column, the column needs to be dropped and recreated.
Do you have any suggestion to solve this problem?
2 Answer(s)
-
0
My migration result is :
protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_AbpOrganizationUnits_AbpOrganizationUnits_ParentId", table: "AbpOrganizationUnits"); //...some DropForeignKey operation on relational tables migrationBuilder.DropForeignKey( name: "FK_OrganizationModeOfStudies_AbpOrganizationUnits_OrganizationId_TenantId", schema: "organization", table: "OrganizationModeOfStudies"); migrationBuilder.DropUniqueConstraint( name: "AK_AbpOrganizationUnits_Id_TenantId", table: "AbpOrganizationUnits"); migrationBuilder.DropIndex( name: "IX_AbpOrganizationUnits_ParentId", table: "AbpOrganizationUnits"); migrationBuilder.DropIndex( name: "IX_AbpOrganizationUnits_TenantId_Code", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "Code", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "CreationTime", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "CreatorUserId", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "DeleterUserId", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "DeletionTime", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "Discriminator", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "DisplayName", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "IsDeleted", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "LastModificationTime", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "LastModifierUserId", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "ParentId", table: "AbpOrganizationUnits"); migrationBuilder.DropColumn( name: "TenantId", table: "AbpOrganizationUnits"); migrationBuilder.RenameTable( name: "AbpOrganizationUnits", newName: "AbpOrganizationUnits", newSchema: "organization"); migrationBuilder.AlterColumn<long>( name: "Id", schema: "organization", table: "AbpOrganizationUnits", type: "bigint", nullable: false, oldClrType: typeof(long), oldType: "bigint") .OldAnnotation("SqlServer:Identity", "1, 1"); migrationBuilder.CreateTable( name: "Organizations", schema: "organization", columns: table => new { Id = table.Column<long>(type: "bigint", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), TenantId = table.Column<int>(type: "int", nullable: false), ParentId = table.Column<long>(type: "bigint", nullable: true), Code = table.Column<string>(type: "nvarchar(95)", maxLength: 95, nullable: false), DisplayName = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), CreatorUserId = table.Column<long>(type: "bigint", nullable: true), LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), LastModifierUserId = table.Column<long>(type: "bigint", nullable: true), IsDeleted = table.Column<bool>(type: "bit", nullable: false), DeleterUserId = table.Column<long>(type: "bigint", nullable: true), DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Organizations", x => x.Id); table.UniqueConstraint("AK_Organizations_Id_TenantId", x => new { x.Id, x.TenantId }); table.ForeignKey( name: "FK_Organizations_Organizations_ParentId", column: x => x.ParentId, principalSchema: "organization", principalTable: "Organizations", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_Organizations_ParentId", schema: "organization", table: "Organizations", column: "ParentId"); migrationBuilder.CreateIndex( name: "IX_Organizations_TenantId_Code", schema: "organization", table: "Organizations", columns: new[] { "TenantId", "Code" }); migrationBuilder.AddForeignKey( name: "FK_AbpOrganizationUnits_Organizations_Id", schema: "organization", table: "AbpOrganizationUnits", column: "Id", principalSchema: "organization", principalTable: "Organizations", principalColumn: "Id", onDelete: ReferentialAction.Restrict); //... }
-
0
Hi,
It seems like this is related to EF Core, you can take a look at https://github.com/dotnet/efcore/issues/20549