FE .Net Core Error: To change the IDENTITY property of a column, the column needs to be dropped and recreated.
Dung Do Tien
Mar 26 2021
395
I created a project with Asp.Net Core Entity Framework 3.1. I used the Code First model. I have a Account
table when I change column Id
to AccountId
but when run the application I got an error: To change the IDENTITY property of a column, the column needs to be dropped and recreated.
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.Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGenerator.Generate(IReadOnlyList1 operations, IModel model)
at Microsoft.EntityFrameworkCore.Migrations.SqlServerMigrationsSqlGenerator.Generate(IReadOnlyList1 operations, IModel model)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration)
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.OperationBase.Execute(Action action) To change the IDENTITY property of a column, the column needs to be dropped and recreated.
public class Account
{
public int Id { get; set; }
// Change to
public int AccountId { get; set; }
}
I used FE Core 3.1, Vs 2019, Window 10.
Thanks for any sugesstions.
Have 1 answer(s) found.
-
A-6
Akhmir Rudmakh Mar 26 2021
I got the same error. I try as below and it worked for me.
- Drop the whole database
- Reinitialize the migration
- Update the database there's nothing wrong with your class models. SQL Server just forced you to recreate the whole thing
I hope it helpful for you.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.