Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresError: relation "User" does not exist #50

Open
mzavattaro opened this issue Jan 9, 2024 · 6 comments
Open

PostgresError: relation "User" does not exist #50

mzavattaro opened this issue Jan 9, 2024 · 6 comments

Comments

@mzavattaro
Copy link

mzavattaro commented Jan 9, 2024

I created a new project using this as the template but ran into an issue when creating a new user. It throws the error PostgresError: relation "User" does not exist. I've tried different variants of environmental variable files but none of them work:

  • .env
  • .env.local
  • .env.development.local

My understanding is that it should be generating the User table on first user creation but it doesn't?

I've referenced the documentation here to no success:
https://vercel.com/docs/storage/vercel-postgres/quickstart

Am I missing something?

next dev --turbo

   ▲ Next.js 14.0.4 (turbo)
   - Local:        http://localhost:3000
   - Environments: .env.development.local

 ✓ Ready in 858ms
 ○ Compiling /register ...
 ✓ Compiled /register in 1061ms
 ✓ Compiled /favicon.ico in 80ms
   Reload env: .env.local
 ⨯ node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js (794:18) @ ErrorResponse
 ⨯ PostgresError: relation "User" does not exist
    at ErrorResponse (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2844:224)
    at handle (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2644:728)
    at TLSSocket.data (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2530:17)
    at TLSSocket.emit (node:events:519:28)
null
   Reload env: .env
 ⨯ node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js (794:18) @ ErrorResponse
 ⨯ PostgresError: relation "User" does not exist
    at ErrorResponse (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2844:224)
    at handle (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2644:728)
    at TLSSocket.data (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2530:17)
    at TLSSocket.emit (node:events:519:28)
null
@Lizitao610
Copy link

I created a new project using this as the template but ran into an issue when creating a new user. It throws the error PostgresError: relation "User" does not exist. I've tried different variants of environmental variable files but none of them work:

  • .env
  • .env.local
  • .env.development.local

My understanding is that it should be generating the User table on first user creation but it doesn't?

I've referenced the documentation here to no success: https://vercel.com/docs/storage/vercel-postgres/quickstart

Am I missing something?

next dev --turbo

   ▲ Next.js 14.0.4 (turbo)
   - Local:        http://localhost:3000
   - Environments: .env.development.local

 ✓ Ready in 858ms
 ○ Compiling /register ...
 ✓ Compiled /register in 1061ms
 ✓ Compiled /favicon.ico in 80ms
   Reload env: .env.local
 ⨯ node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js (794:18) @ ErrorResponse
 ⨯ PostgresError: relation "User" does not exist
    at ErrorResponse (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2844:224)
    at handle (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2644:728)
    at TLSSocket.data (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2530:17)
    at TLSSocket.emit (node:events:519:28)
null
   Reload env: .env
 ⨯ node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/src/connection.js (794:18) @ ErrorResponse
 ⨯ PostgresError: relation "User" does not exist
    at ErrorResponse (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2844:224)
    at handle (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2644:728)
    at TLSSocket.data (/Users/michaelzavattaro/Developer/Github/chronopass-ai/.next/server/chunks/node_modules_34cec9._.js:2530:17)
    at TLSSocket.emit (node:events:519:28)
null

I had the same problem and the code that reported the error was as follows:

let users = pgTable('User', {
  id: serial('id').primaryKey(),
  email: varchar('email', { length: 64 }),
  password: varchar('password', { length: 64 }),
});

error message:


error: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'PgTable'
    |     property 'password' -> object with constructor 'PgVarchar'
    --- property 'table' closes the circle

The reason is not known at this time

@Fr3akyMurk
Copy link

The reason is that the user table along with the db itself that you connect to are not pre-configured in any way.
You have to create your own table "users" and what's required for it.

That is what i had to do and did in order to make it work.
This is not Prisma.

@szbxyz
Copy link

szbxyz commented Feb 17, 2024

Is there a particular reason for them to have switched in the first place ?

@subtubes-io
Copy link

So is there now schema? Or migration scripts to run?

@subtubes-io
Copy link

Also I see they are using this code:
id: serial('id').primaryKey(), serial does not make for a good userid. I am going to change that to uuid at some point.

@Fr3akyMurk
Copy link

If you just now created a project, run db:push and it should automatically create all of the entries to postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants