Гость
Map
Форумы / Java [игнор отключен] [закрыт для гостей] / Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users / 3 сообщений из 3, страница 1 из 1
03.10.2020, 20:47
    #40005184
Blacit
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
Ошибка: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users.
Проблема в том, что я и так знаю, что существует таблица USERS, но у меня в application.properties стоит spring.jpa.hibernate.ddl-auto=validate
Тогда почему эта ошибка всё равно появляется? Может, у меня sql-запрос неверный? Использую posgresql.

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
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;



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


Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
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]
    	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    	at task.homerent.Application.main(Application.java:34) ~[classes/:na]
    Caused by: 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 liquibase.changelog.ChangeSet.execute(ChangeSet.java:646) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.Liquibase.update(Liquibase.java:202) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.Liquibase.update(Liquibase.java:179) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314) ~[liquibase-core-3.8.0.jar:na]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    	... 18 common frames omitted
    Caused by: 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 liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:402) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:59) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:131) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1273) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1255) ~[liquibase-core-3.8.0.jar:na]
    	at liquibase.changelog.ChangeSet.execute(ChangeSet.java:609) ~[liquibase-core-3.8.0.jar:na]
    	... 26 common frames omitted
    Caused by: org.postgresql.util.PSQLException: ОШИБКА: отношение "users" уже существует
    	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284) ~[postgresql-42.2.16.jar:42.2.16]
    	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:279) ~[postgresql-42.2.16.jar:42.2.16]
    	at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.1.jar:na]
    	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.1.jar:na]
    	at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:398) ~[liquibase-core-3.8.0.jar:na]
    	... 31 common frames omitted
...
Рейтинг: 0 / 0
04.10.2020, 06:15
    #40005230
Basil A. Sidorov
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
...
Рейтинг: 0 / 0
04.10.2020, 22:40
    #40005329
Андрей Панфилов
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users
Zzz79
нужно вот это что внизу)
Код: plsql
1.
CREATE TABLE IF NOT EXIST



Ну вот зачем ты фигню советуешь...
Очевидно, что CREATE ... IF NOT EXIST после выполнения переводит БД в неопределенное состояние - мы ничего не знаем про состав колонок и индексов, поэтому вместо CREATE ... IF NOT EXIST нужно всегда писать DROP ... IF EXIST тогда у базы всегда будет детерминированное состояние.


PS. А вообще не мешало бы принять тот факт, что раз БД под управлением liquibase, то значит просто так туда руками больше лазить не нужно.
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Error: ОШИБКА: отношение "users" уже существует [Failed SQL: (0) CREATE TABLE public.users / 3 сообщений из 3, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]