我正在尝试设置我的第一个 t3 应用程序,但我不知道 prisma 是如何工作的。尝试按照教程设置我的数据库,我无法推送我的 prisma 架构。我完全按照教程进行操作,但它仍然不起作用。
命令:
$npx prisma db push
错误:
Error: 'could not find a schema.prisma file that is required for this command'...but my prisma file exists.
代码:
数据库是在行星规模上创建的。使用 create-t3-app 进行目录设置。架构.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"
previewFeatures = ['referentialIntegrity']
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
model Example {
id String @id @default(cuid())
name String
checked Boolean
}
.env
# When adding additional environment variables, the schema in "/src/env.mjs"
# should be updated accordingly.
# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL=mysql://mekxxh8g4nqmo6262jnc:**********@us-east.connect.psdb.cloud/mikes-first-crappy-db?sslaccept=strict
package.json:
"prisma": {
"schema": "./prisma/schema.prisma"
}
我尝试过但没有成功的解决方案:
此站点npx prisma db push
命令时传递架构文件位置。
npx prisma db push --schema='/location/to/schema.prisma'
另外,我建议您从项目的根位置运行命令。这是 db Push 命令的
参考。
在/prisma文件夹中的schema.prisma文件中使用relationMode =“prisma”
此外,在 prisma 的较新更新中,referentialIntergrity id 添加到广义中,无需指定。从generator client 和 datasource db 删除 previewFeatures = ['referentialIntegrity'] 和 referentialIntegrity = "prisma"
您的 schema.prisma 文件应如下所示:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Category {
id String @id @default(cuid())
name String
checked Boolean
}
npx prisma db Push 无法工作或不响应下一个 js
尝试关闭下一个js的另一台服务器,然后再次运行npx prisma db push。 它对我有用