使用DML和DDL脚本

时间:2017-01-18 18:08:46

标签: spring-boot flyway

我正在使用Spring Boot 1.4.1.RELEASE和Flyway。

Flyway在执行架构迁移时无法执行DML脚本。

我的资源文件夹具有以下Flyway结构:

enter image description here

在空数据库上执行Flyway,工作正常。它为数据库创建模式和数据。

但是,一旦应该执行模式迁移(即DML和DDL脚本中的更改),Flyway会显示以下错误消息:

Caused by: org.flywaydb.core.api.FlywayException: Schema `testDB` contains a failed migration to version 1.02 !
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:196) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:156) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:156) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:1059) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.Flyway.execute(Flyway.java:1418) ~[flyway-core-3.2.1.jar:na]
    at org.flywaydb.core.Flyway.migrate(Flyway.java:1006) ~[flyway-core-3.2.1.jar:na]
    at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66) ~[spring-boot-autoconfigure-1.4.1.RELEASE.jar:1.4.1.RELEASE]

我的 application-dev.properties 如下所示:

flyway.enabled=true
flyway.url: jdbc:mysql://localhost:3306
flyway.user: usertest
flyway.password: testtest
flyway.schemas=testDB
flyway.baseline-on-migrate=true
flyway.locations:classpath:/db/migration/dev,/db/data

# Naming strategy
spring.jpa.hibernate.naming.strategy= org.hibernate.cfg.ImprovedNamingStrategy

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql = true
logging.level.org.hibernate.SQL=debug
spring.jpa.hibernate.format_sql=true
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

spring.jpa.generate-ddl = false
spring.jpa.hibernate.ddl-auto =none

1 个答案:

答案 0 :(得分:0)

该异常仅意味着在flyway在迁移执行时识别的一组“新”迁移中,一个或多个脚本导致错误。

Flyway创建了一个表,用于跟踪已执行的迁移脚本及其校验和,您可以验证该表,它应该在执行结果列中包含一个或多个“0”。

当您处于这种情况时(在本地直到开发阶段),您仍然可以简单地删除迁移表中不成功的行,更正有罪的脚本,最后再次启动飞路迁移。