gpt4 book ai didi

liquibase - 重复的列名,在注释变更集并取消注释后在 liquibase 中

转载 作者:行者123 更新时间:2023-12-02 03:04:16 25 4
gpt4 key购买 nike

在我的 Java 本地开发环境中,我错误地注释了一些变更集并运行了应用程序。现在,当我取消注释更改集时,Liquibase 崩溃并提示数据库中的重复列。

有什么方法可以清除 Liquibase 而不必删除整个数据库?似乎有校验和冲突之类的。

    error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/db/changelog/init/33_20191217_sprint31.xml::more attributes for user:::
Reason: liquibase.exception.DatabaseException: Duplicate column name 'option_cgu' [Failed SQL: ALTER TABLE ga_db.api_user ADD option_cgu BIT(1) NULL]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at com.groupama.gari.api.GariApiApplication.main(GariApiApplication.java:16) [classes/:na]
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set classpath:/db/changelog/init/33_20191217_sprint31.xml::more attributes for user::Moncef Fadal GSB850:
Reason: liquibase.exception.DatabaseException: Duplicate column name 'option_cgu' [Failed SQL: ALTER TABLE ga_db.api_user ADD option_cgu BIT(1) NULL]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619) ~[liquibase-core-3.5.3.jar:na]
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51) ~[liquibase-core-3.5.3.jar:na]
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79) ~[liquibase-core-3.5.3.jar:na]
at liquibase.Liquibase.update(Liquibase.java:214) ~[liquibase-core-3.5.3.jar:na]
at liquibase.Liquibase.update(Liquibase.java:192) ~[liquibase-core-3.5.3.jar:na]
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:431) ~[liquibase-core-3.5.3.jar:na]
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:388) ~[liquibase-core-3.5.3.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 18 common frames omitted
Caused by: liquibase.exception.DatabaseException: Duplicate column name 'option_cgu' [Failed SQL: ALTER TABLE ga_db.api_user ADD option_cgu BIT(1) NULL]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:309) ~[liquibase-core-3.5.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55) ~[liquibase-core-3.5.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:113) ~[liquibase-core-3.5.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1277) ~[liquibase-core-3.5.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1259) ~[liquibase-core-3.5.3.jar:na]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:582) ~[liquibase-core-3.5.3.jar:na]
... 26 common frames omitted

最佳答案

看起来不像是校验和冲突。看起来其他变更集已经添加了此列。

但是,如果您想删除有关已执行的changeSet的记录,请按以下步骤操作(尽管这不是一个好的做法,但注释changeSet也不是一个好习惯):

databasechangelogID列中找到您需要的changeSet的id并删除此行。

如果没有这条记录,liquibase 将不知道这个changeSet 曾经被执行过,并将尝试在下一次应用程序启动时执行它。

我建议您尝试添加<preConditions>更改集以避免此类错误。在这种情况下,它可能看起来像这样:

<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="api_user" columnName="option_cgu"/>
</not>
</preConditions>

关于liquibase - 重复的列名,在注释变更集并取消注释后在 liquibase 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59373279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com