Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Migration that adds [Timestamp] column for concurrency fails with invalid value error #2029

Description

@Mattia-Re

I am in the process of adding concurrency checks to my application, thought I'd do this with built-in concurrency features like the TimestampAttribute. However I have this class and when I try Update-Database with a migration that adds the Version column, I get the error Invalid default value for 'Version'.

public class DatabaseEntity
{
    public int Id { get; set; }
    public DateTimeOffset Created { get; set; } = DateTimeOffset.UtcNow;

    [Timestamp]
    public byte[] Version { get; set; } = [];
}

The generated SQL that causes this issue is

ALTER TABLE `Entities` ADD `Version` timestamp(6) NOT NULL DEFAULT '0001-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6);

According to the MySQL documentation

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

Is there a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions