I'm having a problem with Migration EF Core.
To make the scenario clear, I'm assigning it to an existing database, which is intended to use migration for database control from now on. But I am having difficulties.
What I have done so far.
I generated the scaffolding from the existing database.
I added the migration, so it generated all the "Up" for database creation.
So far perfect, everything worked as expected. But from this step every time I generate a new migration he (the migration) insists on creating an Alter Column statement for all tables. For example:
migrationBuilder.AlterColumn<int>(
name: "rac_n_codigo",
table: "tb_rac_raca",
nullable: false,
oldClrType: typeof(int),
oldType: "int")
.Annotation("SqlServer:Identity", "1, 1");
The creation table
migrationBuilder.CreateTable(
name: "tb_rac_raca",
columns: table => new
{
rac_n_codigo = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
rac_c_nome = table.Column<string>(unicode: false, nullable: true),
rac_d_alteracao = table.Column<DateTime>(type: "date", nullable: true),
rac_c_usuario = table.Column<string>(unicode: false, nullable: true),
rac_c_tipo = table.Column<string>(unicode: false, nullable: true),
rac_d_modificacao = table.Column<DateTime>(type: "datetime", nullable: true),
rac_c_unique = table.Column<Guid>(nullable: false, defaultValueSql: "(newid())"),
rac_d_atualizado = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "(getdate())"),
rac_d_inclusao = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "(getdate())")
},
constraints: table =>
{
table.PrimaryKey("PK_tb_rac_raca", x => x.rac_n_codigo);
});
I use ValueGeneratedNever():
_ = builder.Property(x => x.Id).IsRequired().ValueGeneratedNever();
EF Core 5+ In the metadata of the function description is: Configures a property to never have a value generated when an instance of this entity type is saved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With