Задать вопрос
@Blacit

Как решить эту проблему в liquibase?

Ошибка:
отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
. Проблема в том, что я и так знаю, что существует, но у меня в application.properties стоит spring.jpa.hibernate.ddl-auto=validate Тогда почему эта ошибка всё равно появляется? Может, у меня sql-запрос неверный? Использую posgresql.

CREATE TABLE public.users
    (
        id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
        email character varying(255) COLLATE pg_catalog."default" NOT NULL,
        first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        password character varying(255) COLLATE pg_catalog."default" NOT NULL,
        role character varying(255) COLLATE pg_catalog."default",
        status character varying(255) COLLATE pg_catalog."default",
        CONSTRAINT users_pkey PRIMARY KEY (id),
        CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
    )
    
        TABLESPACE pg_default;
    
    ALTER TABLE public.users
        OWNER to root;


Ссылка на код, если не пригодится, то удалю.

2020-10-03 18:10:31.010 ERROR 11936 --- [           main] liquibase.changelog.ChangeSet            : Change Set classpath:db/changelog/v-1.0/01-changeset-users-table.xml::2::vladislav_gil failed.  Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
    (
        id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
        email character varying(255) COLLATE pg_catalog."default" NOT NULL,
        first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        password character varying(255) COLLATE pg_catalog."default" NOT NULL,
        role character varying(255) COLLATE pg_catalog."default",
        status character varying(255) COLLATE pg_catalog."default",
        CONSTRAINT users_pkey PRIMARY KEY (id),
        CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
    )
    
        TABLESPACE pg_default;
    
    ALTER TABLE public.users
        OWNER to root]
    2020-10-03 18:10:31.012  INFO 11936 --- [           main] l.lockservice.StandardLockService        : Successfully released change log lock
    2020-10-03 18:10:31.014  WARN 11936 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: 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/v-1.0/01-changeset-users-table.xml::2::vladislav_gil:
         Reason: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
    (
        id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
        email character varying(255) COLLATE pg_catalog."default" NOT NULL,
        first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        password character varying(255) COLLATE pg_catalog."default" NOT NULL,
        role character varying(255) COLLATE pg_catalog."default",
        status character varying(255) COLLATE pg_catalog."default",
        CONSTRAINT users_pkey PRIMARY KEY (id),
        CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
    )
    
        TABLESPACE pg_default;
    
    ALTER TABLE public.users
        OWNER to root]
    2020-10-03 18:10:31.014  INFO 11936 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
    2020-10-03 18:10:31.026  INFO 11936 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
    2020-10-03 18:10:31.029  INFO 11936 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2020-10-03 18:10:31.038  INFO 11936 --- [           main] ConditionEvaluationReportLoggingListener : 
    
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2020-10-03 18:10:31.044 ERROR 11936 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    org.springframework.beans.factory.BeanCreationException: 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/v-1.0/01-changeset-users-table.xml::2::vladislav_gil:
         Reason: liquibase.exception.DatabaseException: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
    (
        id bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
        email character varying(255) COLLATE pg_catalog."default" NOT NULL,
        first_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        last_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
        password character varying(255) COLLATE pg_catalog."default" NOT NULL,
        role character varying(255) COLLATE pg_catalog."default",
        status character varying(255) COLLATE pg_catalog."default",
        CONSTRAINT users_pkey PRIMARY KEY (id),
        CONSTRAINT uk_6dotkott2kjsp8vw4d0m25fb7 UNIQUE (email)
    )
    
        TABLESPACE pg_default;
    
    ALTER TABLE public.users
        OWNER to root]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	... 31 common frames omitted
  • Вопрос задан
  • 5892 просмотра
Подписаться 1 Сложный 2 комментария
Пригласить эксперта
Ответы на вопрос 1
alfss
@alfss
https://career.habr.com/alfss
потому что оно уже сущетвует. посмотрите в базу.
выполните запрос в бд напрямую через клиент.
spring.jpa.hibernate.ddl-auto=none выставьте
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы