英文:
Getting error on dropping the unique constraint column of a table in liquibase
问题
在尝试删除 app_user_id 列时,我遇到了这个错误。我已经移除了 app_user_id 表的外键关系。但是我不知道为什么只在运行测试用例时出现这个错误。
错误堆栈信息如下:
SEVERE 2/5/20 2:25 PM: liquibase: liquibase/mt-tenant-changelog-postgres.xml: liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil: 变更集 liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil 失败。错误:Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY";SQL 语句:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
INFO 2/5/20 2:25 PM: liquibase: liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil: 成功释放变更日志锁
2020-05-02 14:25:30.600 WARN 9187 --- [ main] ationConfigEmbeddedWebApplicationContext : 在初始化上下文过程中遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': 注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.service.MultiLingualService com.brotech.product.truelocate.config.DatabaseMessageSource.multiLingualService;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualService':注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository':无法创建类型为 [org.springframework.orm.jpa.SharedEntityManagerCreator] 的内部 bean '(inner bean)#3b4f1eb',而正在设置 bean 属性 'entityManager';嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb':在设置构造函数参数时无法解析对 bean 'entityManagerFactory' 的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource':通过工厂方法实例化 bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]:工厂方法'dataSource'抛出异常;嵌套异常是 liquibase.exception.MigrationFailedException:变更集 liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil 失败:
原因:liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY";SQL 语句:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
2020-05-02 14:25:30.607 ERROR 9187 --- [ main] o.s.boot.SpringApplication : 应用启动失败
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': 注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.service.MultiLingualService com.brotech.product.truelocate.config.DatabaseMessageSource.multiLingualService;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualService':注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository':无法创建类型为 [org.springframework.orm.jpa.SharedEntityManagerCreator] 的内部 bean '(inner bean)#3b4f1eb',而正在设置 bean 属性 'entityManager';嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb':在设置构造函数参数时无法解析对 bean 'entityManagerFactory' 的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':注入自动连接的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;嵌套异常是 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource':通过工厂方法实例化 bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]:工厂方法'dataSource'抛出异常;嵌套异常是 liquibase.exception.MigrationFailedException:变更集 liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil 失败:
原因:liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUB
<details>
<summary>英文:</summary>
Getting this error when i tried to delete app_user_id column. I did remove the foreign key relation of app_user_id table. But idk why I am getting this only on running a test case.
stackTrace
SEVERE 2/5/20 2:25 PM: liquibase: liquibase/mt-tenant-changelog-postgres.xml: liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil: Change Set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil failed. Error: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
INFO 2/5/20 2:25 PM: liquibase: liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil: Successfully released change log lock
2020-05-02 14:25:30.600 WARN 9187 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.service.MultiLingualService com.brotech.product.truelocate.config.DatabaseMessageSource.multiLingualService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository': Cannot create inner bean '(inner bean)#3b4f1eb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
2020-05-02 14:25:30.607 ERROR 9187 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.service.MultiLingualService com.brotech.product.truelocate.config.DatabaseMessageSource.multiLingualService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository': Cannot create inner bean '(inner bean)#3b4f1eb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 40 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository': Cannot create inner bean '(inner bean)#3b4f1eb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
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.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 42 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.brotech.product.truelocate.core.repository.MultiLingualRepository com.brotech.product.truelocate.core.service.MultiLingualServiceImpl.multiLingualRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository': Cannot create inner bean '(inner bean)#3b4f1eb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 53 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiLingualRepository': Cannot create inner bean '(inner bean)#3b4f1eb' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3b4f1eb': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
at
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/brotech/product/truelocate/multitenant/DataSourceConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/versions/8.0/mt-tenant-schema-and-data-8.0.xml::TREX-263-drop-column-user-related-fields::Sunil:
Reason: liquibase.exception.DatabaseException: Column may be referenced by "PUBLIC.UQ_DASHBOARD_SUBSCRIPTION_DASHBOARD_COMPONENT_APP_USER_FACILITY"; SQL statement:
ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id [90083-194] [Failed SQL: ALTER TABLE PUBLIC.dashboard_subscription DROP COLUMN app_user_id]
please find the **changeset** below that is very normal syntax:
<dropColumn tableName="dashboard_subscription" columnName="app_user_id" />
</details>
# 答案1
**得分**: 1
有时候外键、索引等会被一些对象关系映射(如Hibernate)或其他数据库用户在您不知情的情况下意外创建,这使得修改数据库模式变得有些棘手。
如果您的 `dropColumn` 变更集因为某个现有外键引用而失败,您可以执行以下步骤:
- 通过某个工具(如DBeaver/PgAdmin等,取决于您的数据库)检查数据库模式,查看是否在要删除的列上存在约束或引用;
- 如果这不起作用,从异常堆栈跟踪中获取阻止列删除的引用名称;
- 创建并执行 `dropForeignKeyConstraint`/`dropIndex`/`dropUniqueConstraint` 等变更集;
- 如果该变更集因为其他引用而失败,那么也要删除该引用;
- 最终您将能够删除所需的列;
<details>
<summary>英文:</summary>
Sometimes foreignKeys, indexes, etc. are being created accidentally by some ORM (like Hibernate) or by another database user without you knowing, which makes altering your DB schema a bit tricky.
If your `dropColumn` changeSet is failing because of some existing foreign key reference on it, you can do the following steps:
- check your database schema via some tool like (DBeaver/PgAdmin/etc, depending on your database) for any constraints or references on the column you want to drop;
- if it doesn't help, get the reference's name that blocks the column drop from exception stack trace;
- create and execute `dropForeignKeyConstraint`/`dropIndex`/`dropUniqueConstraint`/etc. changeSet;
- if that changeSet fails because of some other reference, then drop that reference as well;
- and at the end you'll be able to drop the column you want;
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论