Migraciones assign value by Default

2

I am working on a project with C #, Entity Framework and MySQL.  I wanted to know if you could help me with a "problem" I'm having with migrations. I was working with MySQL version 5.6 and go to version 5.7, the problem (if you can say problem) is that now for the data type Guid assigns me a default value, which I need you not to do

MySQL 5.6

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<Guid>(
        name: "UserId",
        table: "Policy",
        nullable: false
}

MySQL 5.7

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<Guid>(
        name: "CompanyId",
        table: "Policy",
        nullable: false,
        defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
}

How could I avoid assigning a default value in the migration without having to edit the migration file? Could it?

    
asked by Stimpy 18.04.2018 в 17:55
source

1 answer

1

You could try changing the property in the model of your Policy Guid CompanyId to Guid? CompanyId

When declaring CompanyId as nullable ( Guid? ) does not require default value and when generating the migration it will come out:

 migrationBuilder.AddColumn(
            name: "CompanyId",
            table: "Policy",
            nullable: true,
            defaultValue: null);
    
answered by 19.09.2018 в 23:05