org.postgresql.util.PSQLException: ERROR: relation “app_user” does not exist

前端 未结 5 948
醉梦人生
醉梦人生 2021-01-01 18:45

I have an application that I\'m using spring boot and postgres. I\'m getting this error when I try to create a user.

When I run this query on my database, I get the

5条回答
  •  旧巷少年郎
    2021-01-01 19:17

    PostgreSQL is following the SQL standard and in that case that means that identifiers (table names, column names, etc) are forced to lowercase, except when they are quoted. So when you create a table like this:

    CREATE TABLE APP_USER ...
    

    you actually get a table app_user. You apparently did:

    CREATE TABLE "APP_USER" ...
    

    and then you get a table "APP_USER".

    In Spring, you specify a regular string for the table name, in capital letters, but that gets spliced into a query to the PostgreSQL server without quotes. You can check this by reading the PostgreSQL log files: it should show the query that Spring generated followed by the error at the top of your message.

    Since you have very little control over how Spring constructs queries from entities, you are better off using SQL-standard lower-case identifiers.

提交回复
热议问题