0

当我尝试删除 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: 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" />
4

1 回答 1

0

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

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

  • 通过诸如(DBeaver/PgAdmin/etc,取决于您的数据库)之类的工具检查您的数据库架构,以查看您要删除的列上的任何约束或引用;
  • 如果没有帮助,请获取阻止从异常堆栈跟踪中删除列的引用名称;
  • 创建并执行dropForeignKeyConstraint///等dropIndexdropUniqueConstraint变更集;
  • 如果该 changeSet 由于某些其他引用而失败,则也删除该引用;
  • 最后你可以删除你想要的列;
于 2020-05-02T11:57:58.230 回答