mysql - FlywaySqlException : Unable to insert row for version `11` in Schema History table `schema_version` : Field `version_rank` doesn't have a default value 错误

标签 mysql maven spring-boot flyway

我在使用新迁移运行我的 Spring Boot 应用程序时遇到此错误。到目前为止,它已经完成了 10 次迁移。该字段确实没有默认值。不需要默认值,因为 Flyway 应该在该字段中插入值 11。

Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to insert row for version '11' in Schema History table `app`.`schema_version`
--------------------------------------------------------------------------------------------
SQL State  : HY000
Error Code : 1364
Message    : Field 'version_rank' doesn't have a default value

    at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.doAddAppliedMigration(JdbcTableSchemaHistory.java:174) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.schemahistory.SchemaHistory.addAppliedMigration(SchemaHistory.java:170) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:299) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:244) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate.access$100(DbMigrate.java:53) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate$2.call(DbMigrate.java:163) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.command.DbMigrate$2.call(DbMigrate.java:160) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.database.mysql.MySQLNamedLockTemplate.execute(MySQLNamedLockTemplate.java:60) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.database.mysql.MySQLConnection.lock(MySQLConnection.java:80) ~[flyway-core-5.1.4.jar:na]
    at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.lock(JdbcTableSchemaHistory.java:150) ~[flyway-core-5.1.4.jar:na]
pom.xml
<dependency>
  <groupId>org.flywaydb</groupId>
  <artifactId>flyway-core</artifactId>
  <version>5.1.4</version><!--$NO-MVN-MAN-VER$-->
</dependency>
应用程序属性
# Prevent complaints when starting migrations with existing tables.
flyway.baselineOnMigrate = true
flyway.table=schema_version
schema_version
| Field          | Type          | Null | Key | Default           | Extra |
+----------------+---------------+------+-----+-------------------+-------+
| version_rank   | int(11)       | NO   | MUL | NULL              |       |
| installed_rank | int(11)       | NO   | MUL | NULL              |       |
| version        | varchar(50)   | NO   | PRI | NULL              |       |
| description    | varchar(200)  | NO   |     | NULL              |       |
| type           | varchar(20)   | NO   |     | NULL              |       |
| script         | varchar(1000) | NO   |     | NULL              |       |
| checksum       | int(11)       | YES  |     | NULL              |       |
| installed_by   | varchar(100)  | NO   |     | NULL              |       |
| installed_on   | timestamp     | NO   |     | CURRENT_TIMESTAMP |       |
| execution_time | int(11)       | NO   |     | NULL              |       |
| success        | tinyint(1)    | NO   | MUL | NULL              |       |

如果迁移甚至不起作用,我该如何创建迁移以添加默认值?

Flyway 5.1.4,Spring Boot 5.1.13,mysql Ver 15.1 Distrib 10.1.30-MariaDB,适用于 CYGWIN (i686)

最佳答案

如果您绕过 4.x 从 Flyway 3.x 直接升级到 5.x,似乎会出现此问题。

Spring Boot 1.5 默认使用 Flyway 3.x,而 Spring Boot 2.x 默认使用 Flyway 5.x。

来自Flyway 5.0.0 release notes :

Important note for users upgrading from Flyway 3.x: This release no longer supports a schema history table upgrade from Flyway 3.x. You must upgrade to Flyway 4.2.0 first before upgrading to Flyway 5.0.0.

来自Spring Boot 2 Migration Guide :

Upgrading to Spring Boot 2 will upgrade Flyway from 3.x to 5.x. To make sure that the schema upgrade goes smoothly, please follow the following instructions:

  • First upgrade your 1.5.x Spring Boot application to Flyway 4 (4.2.0 at the time of writing), see the instructions for Maven and Gradle.

  • Once your schema has been upgraded to Flyway 4, upgrade to Spring Boot 2 and run the migration again to port your application to Flyway 5.

迁移指南还链接到 a blog post用另一种方法。

提出了关于 Spring Boot skipping Flyway 4.x 的问题和一个反对 Flyway for the version_rank exception你得到了。

看起来像quite a few others遇到了同样的问题。

关于mysql - FlywaySqlException : Unable to insert row for version `11` in Schema History table `schema_version` : Field `version_rank` doesn't have a default value 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52600527/

相关文章:

mysql - 使用 MySQL sql_mode=only_full_group_by 获取组的第一行

mysql - 用于从连接到类别表的项目表中进行选择的 SQL 查询

java - 找不到javax.annotation :com. springsource.javax.annotation :jar:1. 0.0 失败

java - JPA 与 "where"子句不同

java - 使用 Spring Boot 加载本地库

php - 使用json连接android与php和mysql : Not working

mysql - 添加显示 "grouped"值的新列 (mySQL)

maven - Maven 输出中 "<<<"、 ">>>"和 "---"的含义是什么?

eclipse - 如何启用超链接到编译错误的 Maven/Eclipse 集成

java - 如何在 Spring Boot 中 Autowiring OkHttpClient bean?