Получение ошибки при отбрасывании уникального столбца ограничений таблицы в liquibase - PullRequest
0 голосов
/ 02 мая 2020

Получение этой ошибки при попытке удалить столбец 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]

, пожалуйста, найдите changeset ниже, что является очень нормальным синтаксисом:

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

1 Ответ

0 голосов
/ 02 мая 2020

Иногда иностранные клавиши, индексы и т. Д. c. создаются случайно каким-либо ORM (например, Hibernate) или другим пользователем базы данных без вашего ведома, что усложняет изменение схемы БД.

Если ваш dropColumn changeSet не работает из-за какого-то существующего внешнего ключа ссылаясь на него, вы можете выполнить следующие шаги:

  • проверить схему базы данных с помощью какого-либо инструмента, такого как (DBeaver / PgAdmin / et c, в зависимости от вашей базы данных), на наличие каких-либо ограничений или ссылок на столбец, который вы хотите удалить;
  • , если это не поможет, получите имя ссылки, которая блокирует удаление столбца из трассировки стека исключений;
  • создайте и выполните dropForeignKeyConstraint / dropIndex / dropUniqueConstraint / др c. changeSet;
  • если этот changeSet завершится неудачей из-за какой-либо другой ссылки, затем удалите эту ссылку;
  • и в конце вы сможете удалить нужный столбец;
...