没有为占位符表达式提供值

时间:2019-03-05 08:25:50

标签: flyway

尽管设置flyway.placeholderReplacement = false,我仍然看到有关Flyway在sql中没有为占位符表达式提供值的错误

  

错误:意外错误       org.flywaydb.core.api.FlywayException:没有为占位符表达式和条件提供值。检查您的配置!         在org.flywaydb.core.internal.database.oracle.pro.SQLPlusPlaceholderReplacer.replacePlaceholders(SQLPlusPlaceholderReplacer.java:132)         在org.flywaydb.core.internal.util.line.PlaceholderReplacingLine.getLine(PlaceholderReplacingLine.java:36)         在org.flywaydb.core.internal.database.ExecutableSqlScript.extractStatements(ExecutableSqlScript.java:156)         在org.flywaydb.core.internal.database.ExecutableSqlScript(ExecutableSqlScript.java:133)         在org.flywaydb.core.internal.database.oracle.OracleSqlScript。(OracleSqlScript.java:61)         在org.flywaydb.core.internal.database.oracle.OracleDatabase.doCreateSqlScript(OracleDatabase.java:126)         在org.flywaydb.core.internal.database.Database.createSqlScript(Database.java:163)         在org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.getSqlScript(SqlMigrationExecutor.java:96)         在org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.executeInTransaction(SqlMigrationExecutor.java:109)         在org.flywaydb.core.internal.command.DbMigrate.isExecuteGroupInTransaction(DbMigrate.java:312)         在org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:275)         在org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:244)         在org.flywaydb.core.internal.command.DbMigrate.access $ 100(DbMigrate.java:53)         在org.flywaydb.core.internal.command.DbMigrate $ 2.call(DbMigrate.java:163)         在org.flywaydb.core.internal.command.DbMigrate $ 2.call(DbMigrate.java:160)         在org.flywaydb.core.internal.database.Connection $ 1.call(Connection.java:145)         在org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:74)         在org.flywaydb.core.internal.database.Connection.lock(Connection.java:141)         在org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.lock(JdbcTableSchemaHistory.java:150)         在org.flywaydb.core.internal.command.DbMigrate.migrateAll(DbMigrate.java:160)         在org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:138)         在org.flywaydb.core.Flyway $ 1.execute(Flyway.java:947)         在org.flywaydb.core.Flyway $ 1.execute(Flyway.java:910)         在org.flywaydb.core.Flyway.execute(Flyway.java:1238)         在org.flywaydb.core.Flyway.migrate(Flyway.java:910)         在org.flywaydb.commandline.Main.executeOperation(Main.java:161)         在org.flywaydb.commandline.Main.main(Main.java:108)       构建步骤“执行外壳”将构建标记为失败       完成:失败

4 个答案:

答案 0 :(得分:1)

Map<String,String>仅适用于Flyway占位符,不适用于SQL * Plus占位符。

要禁用特定于SQL * Plus的占位符,必须在脚本中包含flyway.placeholderReplacement=false

答案 1 :(得分:0)

我认为,解决此错误的最佳方法-它会覆盖默认前缀和后缀

flyway.placeholderPrefix=$${
flyway.placeholderSuffix=}

由于某些原因,禁用此功能可能无法接受:例如,使用飞行通道变量。

答案 2 :(得分:0)

application.yml 中使用 spring boot。 添加以下 placeholderReplacement: false

 flyway:
    baseline-on-migrate: false
    sql-migration-prefix: V
    table: migration
    placeholderReplacement: false

发生这种情况,因为我的 .SQL 迁移文件中有 ${name} 的 HTML 代码。

所以它试图取代它!我希望它按原样插入到数据库中。

总结:就我而言,我希望它始终被禁用,因为我没有使用它

参考文献Possible Usages In Different Configuration

答案 3 :(得分:0)

如果您的用例与我的类似(您不能禁用占位符,也不能更改前缀),另一种方法是中断占位符值。假设您的 SQL 是:

UPDATE table SET value = '${variable}';

您可以通过使用以下内容来避免 FlyWay 拾取占位符:

UPDATE table SET value = '$' + '{variable}';