EF Code-First: Change datetime field to automated using MySQL

326 views Asked by At

I´m trying to update a MySql Database field to an automated datetime field using Migrations.

Here is the code:

    public partial class AutomatedDateField : DbMigration
    {
        public override void Up()
    {
        this.AlterColumn("Orders", "Created", c => c.DateTime(nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"));
    }

Using SQL Server i would use GETUTCDATE() in defaultValueSql. What should i use in this case?

1

There are 1 answers

0
DanyloStackylo On

You can't use function as default value for column in MySQL.

Possible solution can be found here: Can I use a function for a default value in MySql?