我刚开始使用flywaydb,只是为了进行创建和插入查询的测试并触发了迁移,但它忽略了我所有的创建表脚本:(

我使用-X选项进行调试,发现一条奇怪的行
DEBUG: DDL Transactions Supported: false

似乎我是否实现了它,它将起作用。

有谁遇到过这个问题,如果可以的话,该如何解决?
我已经用clean-init-migrate在新模式上做到了
完整的堆栈跟踪如下:

[ec2-user@ec2 flyway]$ ./flyway -X clean
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Cleaning schema `test` ...
Cleaned schema `test` (execution time 00:00.025s)

[ec2-user@ec2 flyway]$
[ec2-user@ec2 flyway]$ ./flyway -X init
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Schema `test` already exists. Skipping schema creation.
Creating Metadata table: `test`.`schema_version`
DEBUG: Found statement at line 17: CREATE TABLE `test`.`schema_version` (
    `version_rank` INT NOT NULL,
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50) NOT NULL,
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL
) ENGINE=InnoDB
DEBUG: Found statement at line 30: ALTER TABLE `test`.`schema_version` ADD CONSTRAINT `schema_version_pk` PRIMARY KEY (`version`)
DEBUG: Found statement at line 32: CREATE INDEX `schema_version_vr_idx` ON `test`.`schema_version` (`version_rank`)
DEBUG: Found statement at line 33: CREATE INDEX `schema_version_ir_idx` ON `test`.`schema_version` (`installed_rank`)
DEBUG: Found statement at line 34: CREATE INDEX `schema_version_s_idx` ON `test`.`schema_version` (`success`)
DEBUG: Executing SQL: CREATE TABLE `test`.`schema_version` (
    `version_rank` INT NOT NULL,
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50) NOT NULL,
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL
) ENGINE=InnoDB
DEBUG: Executing SQL: ALTER TABLE `test`.`schema_version` ADD CONSTRAINT `schema_version_pk` PRIMARY KEY (`version`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_vr_idx` ON `test`.`schema_version` (`version_rank`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_ir_idx` ON `test`.`schema_version` (`installed_rank`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_s_idx` ON `test`.`schema_version` (`success`)
DEBUG: Metadata table `test`.`schema_version` created.
DEBUG: MetaData table `test`.`schema_version` successfully updated to reflect changes
Schema initialized with version: 1
[ec2-user@ec2 flyway]$ ./flyway -X migrate
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Spring Jdbc available: false
DEBUG: Validating migrations ...
DEBUG: Scanning for filesystem resources at '/home/ec2-user/installables/flyway-3.0/bin/../sql' (Prefix: 'V', Suffix: '.sql')
DEBUG: Scanning for resources in path: /home/ec2-user/installables/flyway-3.0/bin/../sql (/home/ec2-user/installables/flyway-3.0/bin/../sql)
DEBUG: Found filesystem resource: /home/ec2-user/installables/flyway-3.0/bin/../sql/V1__cr_tbl.sql
DEBUG: Found filesystem resource: /home/ec2-user/installables/flyway-3.0/bin/../sql/V2__Add_people.sql
Validated 2 migrations (execution time 00:00.032s)
DEBUG: Schema `test` already exists. Skipping schema creation.
DEBUG: Locking table `test`.`schema_version`...
DEBUG: Lock acquired for table `test`.`schema_version`
Current version of schema `test`: 1
Migrating schema `test` to version 2
DEBUG: Found statement at line 1: insert into PERSON (ID, NAME) values (1, 'Axel')
DEBUG: Found statement at line 2: insert into PERSON (ID, NAME) values (2, 'Mr. Foo')
DEBUG: Found statement at line 3: insert into PERSON (ID, NAME) values (3, 'Ms. Bar')
DEBUG: Executing SQL: insert into PERSON (ID, NAME) values (1, 'Axel')
DEBUG: Rolling back transaction...
DEBUG: Transaction rolled back
ERROR: Migration of schema `test` to version 2 failed! Please restore backups and roll back database and code!
DEBUG: MetaData table `test`.`schema_version` successfully updated to reflect changes
ERROR: Unexpected error
org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: Error executing statement at line 1: insert into PERSON (ID, NAME) values (1, 'Axel')
    at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:91)
    at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:73)
    at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:287)
    at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:285)
    at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
    at org.flywaydb.core.internal.command.DbMigrate.applyMigration(DbMigrate.java:285)
    at org.flywaydb.core.internal.command.DbMigrate.access$800(DbMigrate.java:46)
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:207)
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:156)
    at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
    at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:156)
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:864)
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:811)
    at org.flywaydb.core.Flyway.execute(Flyway.java:1171)
    at org.flywaydb.core.Flyway.migrate(Flyway.java:811)
    at org.flywaydb.commandline.Main.executeOperation(Main.java:120)
    at org.flywaydb.commandline.Main.main(Main.java:88)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.PERSON' doesn't exist
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2812)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2761)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:894)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:732)
    at org.flywaydb.core.internal.dbsupport.JdbcTemplate.executeStatement(JdbcTemplate.java:235)
    at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:89)
    ... 16 more

最佳答案

这仅表示您的数据库不支持DDL事务。如果需要,可以使用PostgreSQL,DB2或SqlServer之类的其他名称。

现在关于为什么不选择脚本的问题,从您的问题中无法分辨出来。

从入门教程开始,一旦成功,请使其适应您的项目。

关于java - 如何打开DDL事务支持?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25976969/

10-13 05:22