B
B
Blacit2020-10-03 17:15:53
PostgreSQL
Blacit, 2020-10-03 17:15:53

How to solve this problem in liquibase?

Mistake:

отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
. application.propertiesThe problem is that I already know what exists, but I have it. spring.jpa.hibernate.ddl-auto=validateThen why does this error still appear? Maybe my sql query is wrong? I use 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;


Link to the code, if not useful, then delete.

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alfss, 2020-10-04
@alfss

because it already exists. look at the base.
query the database directly through the client.
set spring.jpa.hibernate.ddl-auto=none

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question