0

将 Mysql 与 dotnet 核心 API 一起使用,我的实体具有 DateTime 类型列。在迁移中,它得到一个错误

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,
4

1 回答 1

1

您需要指定您正在使用的服务器版本和类型,尤其是在您使用非常旧(且不受支持)版本的 MySQL 的情况下。

添加迁移时最简单的方法是在类中实现IDesignTimeDbContextFactory<TContext>接口,该接口仅在运行 ef 核心工具时使用:

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

        optionsBuilder.UseMySql(
            "server=127.0.0.1;port=3306;user=root;password=;database=so62725308",
            mySqlOptions => mySqlOptions
                .ServerVersion(new Version(5, 5, 51), ServerType.MySql)); // <-- the server version

        return new BloggingContext(optionsBuilder.Options);
    }
}
于 2020-07-10T09:05:12.930 回答