database 检测到的已解决迁移未应用于 Flyway 上的数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36077766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detected resolved migration not applied to database on flyway
提问by Joey Yi Zhao
We are using flyway to manage database schema version and we are facing a problem. Since we work as a team and use git as our source code management, there would be some cases that different people update database schema on their own local repo. If that happens, we will get
我们正在使用 flyway 来管理数据库模式版本,但我们遇到了一个问题。由于我们作为一个团队工作并使用 git 作为我们的源代码管理,因此在某些情况下,不同的人会在他们自己的本地 repo 上更新数据库架构。如果发生这种情况,我们将得到
Detected resolved migration not applied to database: 2016.03.17.16.46"
检测到未应用于数据库的已解决迁移:2016.03.17.16.46"
The time "2016.03.17.16.46" was added by another person and I have already applied some timestamp later than that time. If that happens, we have to clean all database tables and create them again. We have tried to set false on validateOnMigrate
and did flywayClean
, but nothing help. Is there another way to change that?
时间“2016.03.17.16.46”是由另一个人添加的,我已经在该时间之后应用了一些时间戳。如果发生这种情况,我们必须清理所有数据库表并重新创建它们。我们试图将 false 设置为 onvalidateOnMigrate
并做了flywayClean
,但没有任何帮助。有没有另一种方法来改变它?
回答by Axel Fontaine
The migration option outOfOrder
is your friend here. Set it to true to allow inserting those migrations after the fact.
迁移选项outOfOrder
是您的朋友。将其设置为 true 以允许在事后插入这些迁移。
On the command line, run:
在命令行上,运行:
flyway -outOfOrder=true migrate
Or if you use the Maven plugin:
或者,如果您使用 Maven 插件:
mvn -Dflyway.outOfOrder=true flyway:migrate
回答by Alex
I faced similar problem when switching from one git branch to another and tried to run
flyway:migrate
.
For example when I was on branch 'release_4.6.0' I didn't have migrations on my local machine from branch 'release_4.7.0' so
I received next error
FlywayException: Validate failed: Detected applied migration not resolved locally
.
The solution that worked for me is to set ignoreMissingMigrations
flyway option to true.
In maven it looks like
从一个 git 分支切换到另一个并尝试运行 .git 分支时,我遇到了类似的问题
flyway:migrate
。例如,当我在分支 'release_4.6.0' 上时,我的本地机器上没有从分支 'release_4.7.0' 进行迁移,所以我收到了下一个错误
FlywayException: Validate failed: Detected applied migration not resolved locally
。对我ignoreMissingMigrations
有用的解决方案是将flyway 选项设置为 true。在Maven中它看起来像
flyway:migrate -Dflyway.ignoreMissingMigrations=true
Maybe it's not an answer for this question, but it can be helpful for those who faced the same problem as me.
也许这不是这个问题的答案,但它可以帮助那些与我面临同样问题的人。
Here you can find more details: https://flywaydb.org/documentation/commandline/migrate#ignoreMissingMigrations
在这里您可以找到更多详细信息:https: //flywaydb.org/documentation/commandline/migrate#ignoreMissingMigrations
回答by Harsh
just add spring.flyway.ignore-missing-migrations=true
to your properties file if you are using spring-boot.
spring.flyway.ignore-missing-migrations=true
如果您使用的是 spring-boot,只需添加到您的属性文件中。
This will ignore previous migrations.
这将忽略以前的迁移。
回答by azevik
You can also put it in your application.properties
file if you want to apply the migrations when starting up the app:
application.properties
如果你想在启动应用程序时应用迁移,你也可以把它放在你的文件中:
spring.flyway.out-of-order=true
回答by nikiforovpizza
In my case, I just renamed my migration file to some other name and then renamed it back – just to update modification date of the file. And it worked.
就我而言,我只是将我的迁移文件重命名为其他名称,然后将其重新命名——只是为了更新文件的修改日期。它奏效了。
回答by WesternGun
..Or you just clean the flyway_schema_history
table and bootrun
again.
..或者你只是一次又一次地清洁flyway_schema_history
桌子bootrun
。
Make sure your SQL sequences are all idempotent.
确保您的 SQL 序列都是幂等的。
Then, in the next launch, you will see lines of logs like:
然后,在下次启动时,您将看到如下日志行:
o.f.c.i.s.DefaultSqlScriptExecutor : DB: relation "transaction_attempt" already exists, skipping (SQL State: 42P07 - Error Code: 0)
o.f.c.i.s.DefaultSqlScriptExecutor : DB: relation "provider" already exists, skipping (SQL State: 42P07 - Error Code: 0)
Don't forget to dump the data in production environment.
不要忘记在生产环境中转储数据。