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?
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 tryUpdate-Databasewith a migration that adds theVersioncolumn, I get the errorInvalid default value for 'Version'.The generated SQL that causes this issue is
According to the MySQL documentation
Is there a workaround?