我开始在我的spring托管java项目中使用flyway(我也使用了hibernate)。
我遵循了flyway的文档。我配置了maven插件,一切正常。
尝试使用maven插件进行清理,初始化和迁移,一切正常。
相反,如果我尝试运行我的应用程序(我使用我的flyway bean):
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="dataSource" />
</bean>
我明白了:
不幸的是,由于我不理解的迁移过程中的错误,我的应用程序无法启动:
31/10/2014 11:03:34 INFO DbSupportFactory:43 - Database: jdbc:h2:~/db/db (H2 1.4)
31/10/2014 11:03:34 INFO DbValidate:43 - Validated 1 migration (execution time 00:00.015s)
31/10/2014 11:03:34 INFO MetaDataTableImpl:43 - Creating Metadata table: "PUBLIC"."schema_version"
31/10/2014 11:03:34 INFO DbMigrate:43 - Current version of schema "PUBLIC": << Empty Schema >>
31/10/2014 11:03:34 INFO DbMigrate:43 - Migrating schema "PUBLIC" to version 3.0.0
31/10/2014 11:03:34 ERROR ContextLoader:331 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in ServletContext resource [/WEB-INF/spring/app-jpa-config.xml]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to insert row for version '3.0.0' in metadata table "PUBLIC"."schema_version"
...
...
...
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY_KEY_6 ON PUBLIC.""schema_version""(""version"") VALUES ( /* 3 */ CAST('3.0.0' AS VARCHAR_IGNORECASE) )"; SQL statement:
INSERT INTO "PUBLIC"."schema_version" ("version_rank","installed_rank","version","description","type","script","checksum","installed_by","execution_time","success") VALUES (?, ?, ?, ?, ?, ?, ?, USER(), ?, ?) [23505-182]
所以似乎是一个重复的异常,但它很奇怪。在此之后,我看到了db并且总是看起来是正确的:
所以我的问题是:出了什么问题?飞路是否试图进行两次迁移?
由于
答案 0 :(得分:1)
我解决了这个问题。最后是一个愚蠢的问题:在我的sql脚本中还有schema_version的创建。当然这是一个错误。
在脚本中删除该部分一切正常!