示例错误消息:
org.springframework.beans.factory.BeanCreationException:错误 创建在类路径中定义的名称为“ flywayInitializer”的bean 资源 [org / springframework / boot / autoconfigure / flyway / FlywayAutoConfiguration $ FlywayConfiguration.class]: 调用init方法失败;嵌套异常为 org.flywaydb.core.api.FlywayException:验证失败:迁移 迁移版本0006.0的校验和不匹配
如何在不影响flyway_schema_history的flyway脚本的情况下更改数据库表?
例如,我需要使用alter命令更改表名,但是执行flyway迁移脚本不会失败。
任何建议,谢谢。
注意:-我不想从表flyway_schema_history中删除脚本条目。
答案 0 :(得分:2)
有几种方法可以做到这一点:-
1)创建一个具有递增版本的新脚本文件。放置您的DDL命令以更改此文件中的表。然后运行迁移。
2)如果不想从schema_version表中删除条目,则可以更改该表中的校验和值。要计算校验和,请使用从org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver
复制的以下方法。您可以为资源参数传递null
:-
/**
* Calculates the checksum of this string.
*
* @param str The string to calculate the checksum for.
* @return The crc-32 checksum of the bytes.
*/
/* private -> for testing */
static int calculateChecksum(Resource resource, String str) {
final CRC32 crc32 = new CRC32();
BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
try {
String line;
while ((line = bufferedReader.readLine()) != null) {
crc32.update(line.getBytes("UTF-8"));
}
} catch (IOException e) {
String message = "Unable to calculate checksum";
if (resource != null) {
message += " for " + resource.getLocation() + " (" + resource.getLocationOnDisk() + ")";
}
throw new FlywayException(message, e);
}
return (int) crc32.getValue();
}
3)如果您使用的是Flyway Pro 5+版本,则可以回滚迁移https://flywaydb.org/getstarted/undo。
The answers here已过时,但仍然可以为您提供帮助。
答案 1 :(得分:0)
听起来您可能处于以下两种情况之一: