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,
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>();
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);
}
}
User contributions licensed under CC BY-SA 3.0