fix: MySQL5.7 NO_ZERO_IN_DATE NO_ZERO_DATE

This commit is contained in:
devezhao-mbp 2019-12-22 17:09:56 +08:00
parent f7dbb53aa1
commit 9bb372bde2

View file

@ -259,6 +259,16 @@ public class Entity2Schema extends Field2Schema {
Dialect dialect = Application.getPersistManagerFactory().getDialect();
Table table = new Table(entity, dialect);
String[] ddls = table.generateDDL(false, false);
// Fix MySQL5.7 NO_ZERO_IN_DATE NO_ZERO_DATE
for (int i = 0; i < ddls.length; i++) {
String ddl = ddls[i];
if (ddl.contains("0000-00-00")) {
ddls[i] = ddl
.replace("default '0000-00-00 00:00:00'", "default current_timestamp")
.replace("default '0000-00-00'", "default current_date");
}
}
try {
Application.getSQLExecutor().executeBatch(ddls);
} catch (Throwable ex) {