我已经使用所有必要的凭据配置了我的 Dockerfile,并且我的 Docker 容器运行顺利。但是,当我执行
npx prisma migrate dev --name create_user_table
时,遇到以下错误:
这是我的 docker compose.yml
version: '3.4'
services:
postgres:
container_name: threads-db
image: postgres
ports:
- "5432:5432" #default port of postgres:5432
volumes:
- postgres_data:/var/lib/postgresql/data #store the data from this add to volume postgres data such that upon shutting off, the data is still stored in our local machine
environment:
POSTGRES_USER: postgres #Use this in DATABASE_URL-user in .env
POSTGRES_DB: threads #db name
POSTGRES_PASSWORD: postgres #do not use @ -password
volumes:
postgres_data:
这是我的 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 @id @default(uuid())
firstName String @map("first_name") //at code level-firstName, in db-first_name ->mapping is not compulsory.
lastName String @map("last_name")
proflieImgURL String @map("profile_img_url")
email String @unique //will take email as it is for db
password String
salt String
@@map("users") //will make the table as users
}
这是我的.env-
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/threads"
我正在尝试将 Prisma 架构迁移到在 Docker 容器中运行的 PostgreSQL 数据库。尽管验证了所有字段,我仍然遇到错误。
我很困惑我可能哪里出了问题。有人可以帮忙找出问题所在吗?任何帮助将不胜感激!
npx prisma migrate dev --name init
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/threads?schema=public"
所以尝试通过
?schema=public
对于docker,你可以检查这个repo。它运行得非常顺利:https://github.com/tomanagle/awesome-docker-compose/blob/main/postgres/docker-compose.yml