我使用 Liquibase 的 generateChangeLog 命令为现有数据库生成了更改日志。但是,当我尝试运行它时,会引发 SQLSyntaxErrorException。
Caused by: java.sql.SQLSyntaxErrorException: 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 'databaseChangeLog:
- changeSet:
id: 1595846089000-1
author: A (gen' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.21.jar:8.0.21]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.21.jar:8.0.21]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.21.jar:8.0.21]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) ~[mysql-connector-java-8.0.21.jar:8.0.21]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.21.jar:8.0.21]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.5.jar:na]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:352) ~[liquibase-core-3.6.3.jar:na]
... 31 common frames omitted
更改日志
databaseChangeLog:
- changeSet:
id: 1595846089000-1
author: A123456 (generated)
changes:
- createTable:
columns:
- column:
constraints:
primaryKey: true
name: id
type: VARCHAR(36)
- column:
name: message
type: LONGTEXT
- column:
name: output
type: LONGTEXT
- column:
name: result
type: VARCHAR(16)
tableName: task
我尝试以不同的格式(xml、yaml、sql)生成文件,但即使语法有效,它们都失败并出现相同的错误。
我认为生成的日志字符集可能是一个问题,所以我尝试将以下内容添加到连接 URL。
&useJvmCharsetConverters=true
看到这个问题后,我还确保文件是 UTF-8(没有 bom)。
运行 Liquibase 3.6.3
任何帮助将不胜感激!
编辑以添加主更改日志:
databaseChangeLog:
- changeSet:
id: 1
author: A123456
dbms: mysql
labels: initial-migration
preConditions:
- onFail: MARK_RAN
- onError: MARK_RAN
- not:
tableExists:
schemaName: pd
tableName: task
changes:
- sqlFile:
path: initial-migration.yaml
relativeToChangelogFile: true
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/db/changelog/db.changelog-master.yaml::1::A123456:
Reason: liquibase.exception.DatabaseException: You have an error in your SQL syntax;