Entity Framework Core 2 HasDefaultValueSql() not working with MySQL

ef-core-2.0 ef-migrations entity-framework entity-framework-core mysql

Question

So, I have a Model with a prop like this:

public DateTime Date { get; set; }

Im trying to set a default value to this field like this:

modelBuilder.Entity<Record>().Property(r => r.Date).HasDefaultValueSql("NOW()");

The problem is that the database column default value isnt set. When I use the "NOW()" function, the migration works but as I said, the column default isnt set in the database. And when I try other MySql datetime functions I get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

What am I missing here?

1
4
3/2/2018 8:56:08 PM

Popular Answer

I think you have to use "getdate()" instead of "NOW()

0
4/4/2019 11:43:00 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow