DateTime Error with mysql using dotnet core


Using Mysql with dotnet core API, my entity has on DateTime type column. In migration, it getting an error as

MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL,
    `ModifiedAt` datetime(6) NOT NULL,
asked on Stack Overflow Jul 4, 2020 by Sajid • edited Sep 23, 2020 by lauxjpn

1 Answer


You need to specify the server version and type you are using, especially in your case, where you are using a very old (and unsupported) version of MySQL.

The easiest way to do this when adding migrations, is to implement the IDesignTimeDbContextFactory<TContext> interface in a class, that will only be used when running the ef core tools:

public class BloggingDesignTimeContextFactory : IDesignTimeDbContextFactory<BloggingContext>
    public BloggingContext CreateDbContext(string[] args)
        var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();

            mySqlOptions => mySqlOptions
                .ServerVersion(new Version(5, 5, 51), ServerType.MySql)); // <-- the server version

        return new BloggingContext(optionsBuilder.Options);
answered on Stack Overflow Jul 10, 2020 by lauxjpn

User contributions licensed under CC BY-SA 3.0