我已经用Vercel创建了Postgres数据库,当尝试使用命令 npx prisma migrate dev 迁移时,我收到:
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "verceldb", schema "public" at "ep-curly-resonance-50034155.eu-central-1.postgres.vercel-storage.com:5432"
Error: Schema engine error:
ERROR: password authentication failed for user ''
字符串
我在后端很弱,不知道如何帮助你理解这个问题,所以我留下了这些prisma和.env代码,以防你需要它们:
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("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
model Form {
id Int @id @default(autoincrement())
userId String
createdAt DateTime @default(now())
published Boolean @default(false)
name String
description String @default("")
content String @default("[]")
visits Int @default(0)
submissions Int @default(0)
shareURL String @default(uuid())
FormSubmissions FormSubmissions[]
}
model FormSubmissions {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
formId Int
form Form @relation(fields: [formId], references: [id])
content String
}
型
.env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_aW1tZW5zZS1mYWxjb24tNzQuY2xlcmsuYWNjb3VudHMuZGV2JA
CLERK_SECRET_KEY=sk_test_w9Pc0w9eCvYrcl4iwogc28r2YLPbIyhKyZRAi8Sw7A
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/
# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# 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
POSTGRES_PRISMA_URL="postgres://:@ep-curly-resonance-50034155-pooler.eu-central-1.postgres.vercel-storage.com:5432/verceldb?pgbouncer=true&connect_timeout=15"
POSTGRES_URL_NON_POOLING="postgres://:@ep-curly-resonance-50034155.eu-central-1.postgres.vercel-storage.com:5432/verceldb"
型
2条答案
按热度按时间7nbnzgx91#
在posgresql db的.env文件中没有任何用户名和密码。
连接URL也可以接受参数。下面是与上面相同的示例,其中三个参数的占位符值以小写字母表示:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?KEY1=VALUE&KEY2=VALUE&KEY3=VALUE
如果你在Versel上创建数据库,你需要在选项卡“.env.local”中找到名为“POSTGRES_USER”和“POSTGRES_PASSWORD”的环境变量,或者只是复制它们并粘贴到你的.env文件中。
crcmnpdw2#
这里不要写变量名,写变量的实际值
POSTGRES_PRISMA_URL=“postgres:POSTGRES_USER:POSTGRES_PASSWORD@ep-curly-resonance-50034155-pooler.eu-central-1.postgres.vercel-storage.com:5432/verceldb?pgbouncer=true&connect_timeout=15“
POSTGRES_URL_NON_POOLING=“postgres:POSTGRES_USER:POSTGRES_PASSWORD@ep-curly-resonance-50034155.eu-central-1.postgres.vercel-storage.com:5432/verceldb“
env snippet
POSTGRES_USER和POSTGRES_PASSWORD的值将在代码片段中可用!您可以在上面的链接中查看它!