0
votes

Hello guys, I deleted 4 sql files from flyway and the corresponding schema version rows from the database, It's an spring mvc project. I tried to rollback all the files but nothing changed. I am using intellij. Any ideas how can I solve this?

Error creating bean with name 'flyway' defined in ServletContext resource [/WEB-INF/applicationContext-db.xml]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not aenter code herepplied to database: 0.1.10
    2020-12-17 22:21:21,189 INFO  HikariPool - springHikariCP - Close initiated...
    2020-12-17 22:21:21,205 INFO  HikariPool - springHikariCP - Closed.
    2020-12-17 22:21:21,205 ERROR ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in ServletContext resource [/WEB-INF/applicationContext-db.xml]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not applied to database: 0.1.10
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)
1
here is the second part of the error at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) - ChrisBi

1 Answers

0
votes

The error means that Flyway can see a migration file (V0.1.10) which isn't the latest - that is, there are higher numbered migrations in the history table - but is has no record of applying it in the past and it's not explicitly being ignored. The quick workround is to add the config flag -ignoreIgnoredMigrations=true

As a matter of principle, though, you should not delete migration files and alter the history table. Once you've done that, there is both the possibility of errors if you introduce a mismatch anywhere, and you've also broken the idea that the collection of scripts (source controlled, hopefully!) allows you to faithfully reproduce the database state with flyway clean migrate.