1
I want to add a column like BIT
to an existing table with a default value 1
via Migrations. The challenge is...we have in the company a standard for the name of constraints
and it is not legal the name created automatically by EF.
Below the code to add the column:
public override void Up()
{
AddColumn("dbo.RODADA_DESAFIO", "FL_STATUS", c => c.Boolean(nullable: false, defaultValue: true));
}
Is there a parameter I can pass in the AddColumn
to define the name of constraint
default or else some other way to do it?
I tried that way:
public override void Up()
{
AddColumn("dbo.RODADA_DESAFIO", "FL_STATUS", c => c.Boolean(nullable: false))
Sql("ALTER TABLE RODADA_DESAFIO ADD CONSTRAINT DF_RODADADESAFIO_STATUS DEFAULT (1) FOR FL_STATUS");
}
However the following error appears:
Column already has a DEFAULT bound to it.
Could not create constraint or index. See previous errors.
NOTE: Column does not exist yet in the bank.
Use the Fluent API.
– Netinho Santos
Could you give me an example?
– Mr. Mister
This tutorial exemplifies well. http://www.entityframeworktutorial.net/code-first/configure-property-mappings-using-fluent-api.aspx
– Netinho Santos
Valeu man, however I did not find anything about default constraints in this tutorial.
– Mr. Mister