postgresql 我如何在psql命令行中找到我用Prisma放入postgres数据库的行?

ca1c2owp  于 2023-04-29  发布在  PostgreSQL
关注(0)|答案(1)|浏览(117)

我用棱镜创建了一个模式。下面是我的Prisma文件的样子:
schema.prisma

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id            String       @default(cuid()) @id
  name          String?
  email         String?   @unique
  createdAt     DateTime  @default(now()) @map(name: "created_at")
  updatedAt     DateTime  @updatedAt @map(name: "updated_at")
  is_confirmed  Boolean   @default(false)
  confirm_key   String
  @@map(name: "users")
}

我在docker容器中有一个正在运行的Postgres示例,我在env文件中引用了它:
.env

# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://POSTGRES_USERNAME:PASSWORD@localhost:5432/DB_NAME?schema=users"

我运行了命令npx prisma db push,它似乎工作,因为我在我的终端中得到了这个:

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "DB_NAME", schema "users" at "localhost:5432"

🚀  Your database is now in sync with your Prisma schema. Done in 132ms

Running generate... (Use --skip-generate to skip the generators)

added 2 packages, and audited 338 packages in 5s

117 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

✔ Generated Prisma Client (4.13.0 | library) to ./node_modules/@prisma/client in 51ms

我用npx prisma studio打开了prisma studio
我通过Prisma Studio添加了2个条目:

但是当我用psql登录数据库时,我找不到我输入到数据库中的数据:

MYUSERNAME@MYCOMPUTERNAME my-current-directory % docker exec -it DOCKERCONTAINERNAME bash
root@DOCKERCONTAINERID:/# psql -h localhost -U POSTGRES_USERNAME DB_NAME
psql (15.2 (Debian 15.2-1.pgdg110+1))
Type "help" for help.

DB_NAME=> SELECT * FROM User;
        user        
--------------------
 POSTGRES_USERNAME
(1 row)

DB_NAME=>

我没有看到任何条目。我做错了什么?

btqmn9zl

btqmn9zl1#

这是一个简单的修复。DATABASE_URL="postgresql://POSTGRES_USERNAME:PASSWORD@localhost:5432/DB_NAME?schema=users"应该设置为DATABASE_URL="postgresql://POSTGRES_USERNAME:PASSWORD@localhost:5432/DB_NAME?schema=public"。请注意,我将schema=users更改为schema=public

相关问题