错误信息:
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 中删除脚本条目。
有几种方法可以做到这一点:-
创建一个版本递增的新脚本文件。将用于更改此文件中的表的 DDL 命令放入其中。然后运行迁移。
如果您不想从 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();
}
如果您使用的是 Flyway Pro 5+ 版本,您可以回滚迁移https://flywaydb.org/getstarted/undo。
这里的答案已经过时,但仍然可以帮助你。
听起来您可能处于以下两种情况之一:
要在本地解决此错误而不删除整个数据库: