diff --git a/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/diff/DiffResult.java b/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/diff/DiffResult.java index 090f634..8d1ee55 100644 --- a/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/diff/DiffResult.java +++ b/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/diff/DiffResult.java @@ -8,6 +8,7 @@ import org.springframework.util.ObjectUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -103,7 +104,7 @@ public void resolveCreateSql() { // 创建key Key create = (Key) difference; String createSql = create.getCreateSql(); - this.sqlList.add(createSql); + this.sqlList.addAll(Arrays.asList(createSql.split("\n"))); } else if (difference instanceof Column) { // 创建字段 Column create = (Column) difference; diff --git a/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/entity/structure/Key.java b/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/entity/structure/Key.java index 7af7a64..1cba4eb 100644 --- a/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/entity/structure/Key.java +++ b/mysql-migrate/src/main/java/cn/codeforfun/migrate/core/entity/structure/Key.java @@ -93,7 +93,7 @@ public String getCreateSql() { sb.append("ALTER TABLE `").append(this.tableName).append("` ADD UNIQUE KEY `").append(this.name).append("` (`").append(this.columnName).append("`);"); } else { // 外键 - sb.append("ALTER TABLE `").append(this.tableName).append("` ADD KEY `").append(this.name).append("` (`").append(this.columnName).append("`);"); + sb.append("ALTER TABLE `").append(this.tableName).append("` ADD KEY `").append(this.name).append("` (`").append(this.columnName).append("`);\n"); sb.append("ALTER TABLE `").append(this.tableName).append("` ADD CONSTRAINT `").append(this.name).append("` ") .append("FOREIGN KEY (`").append(this.columnName).append("`) ") .append("REFERENCES `").append(this.referencedTable).append("` ")