在liquibase中删除表的唯一约束列时出错



尝试删除app_user_id列时出现此错误。我确实删除了app_user_id表的外键关系。但我明白为什么我只在运行一个测试用例时得到这个。

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]

请在下面找到变更集,这是非常正常的语法:

<dropColumn tableName="dashboard_subscription" columnName="app_user_id" />

有时,某些ORM(如Hibernate(或其他数据库用户在您不知情的情况下意外创建了foreignKeys、索引等,这使得更改数据库模式有点棘手。

如果您的dropColumnchangeSet由于其上存在某些外键引用而失败,您可以执行以下步骤:

  • 通过一些工具,如(DBeaver/PgAdmin/etc,取决于您的数据库(检查您的数据库架构,以查看您想要删除的列上的任何约束或引用
  • 如果没有帮助,获取阻止异常堆栈跟踪中的列删除的引用的名称
  • 创建并执行dropForeignKeyConstraint/dropIndex/dropUniqueConstraint/等。changeSet
  • 如果该changeSet由于其他引用而失败,那么也删除该引用
  • 最后,你可以放下你想要的栏

最新更新