当我运行 GraphQL 查询时,我从 prisma 收到此错误消息。
Environment variable not found: DATABASE_URL.\n --> schema.prisma:6\n | \n 5 | provider = \"postgresql\"\n 6 | url = env(\"DATABASE_URL\")\n | \n\nValidation Error Count: 1",
Run Code Online (Sandbox Code Playgroud)
起初,我的任何项目文件夹中都没有 .env 文件,然后我使用数据库 URL 的链接添加了它,但仍然无法正常工作。这是文件夹结构:
这就是我的.env文件中的内容 -
DATABASE_URL="postgres://postgres:mypassword@db.pqtgawtgpfhpqxpgidrn.supabase.co:5432/postgres"
Run Code Online (Sandbox Code Playgroud) 我正在使用 NextJS 框架和 Prisma 开发 ReactJS 项目来管理数据库的连接和查询。
在我的本地项目中,找到了支持模型,当我在 API 中使用它并构建我的项目时,一切正常。
但是,当我将项目推送到生产服务器(Plesk)时,构建会向我显示此打字稿错误,因为它找不到支持模型:
./src/pages/api/support/index.ts:27:26
Type error: Property 'support' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.
Run Code Online (Sandbox Code Playgroud)
该路径./src/pages/api/support/index.ts是我要使用支持模型的地方
我的prisma.schema:
datasource db {
provider = "mysql"
url = env("DATABASE_CONNECTION")
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @unique @default(autoincrement())
gender String?
firstName String
lastName String
email String @unique
phone String
birthday DateTime?
income Float? …Run Code Online (Sandbox Code Playgroud) 我无法在同一应用程序中使用多个数据库。我们如何使用多个数据源。我们可以为不同的数据库连接生成多个“schema.prisma”吗?
我在docker中遇到连接问题.我使用官方的mysql 5.7图像和Prisma服务器.当我通过prisma cli开始它时,使用docker composeunderneath(在这里描述)一切正常.
但我需要通过docker api以编程方式启动此容器,在这种情况下,应用程序中的连接将被删除[Note] Aborted connection 8 to db: 'unconnected' user: 'root' host: '164.20.10.2' (Got an error reading communication packets).
所以我做了什么:
创建桥接网络:
const network = await docker.network.create({
Name: manifest.name + '_network',
IPAM: {
"Driver": "default",
"Config": [
{
"Subnet": "164.20.0.0/16",
"IPRange": "164.20.10.0/24"
}
]
}});
Run Code Online (Sandbox Code Playgroud)创建mysql容器并将其附加到网络
const mysql = await docker.container.create({
Image: 'mysql:5.7',
Hostname: manifest.name + '-mysql',
Names: ['/' + manifest.name + '-mysql'],
NetworkingConfig: {
EndpointsConfig: {
[manifest.name + '_network']: …Run Code Online (Sandbox Code Playgroud)我知道目前Prisma不支持按多个标量字段排序(请参阅此问题: https: //github.com/prisma/prisma/issues/62)。但是,我想知道是否有人找到了解决此问题的解决方案,而无需使用executeRaw 突变(原始SQL),因为我的代码中有很多地方需要按多个字段进行排序,但我不想在很多地方都使用executeRaw。我将不胜感激任何建议。谢谢你!
每当我尝试使用 @supabase/supabase-js 查询数据库时,都会收到错误。
error: {
hint: null,
details: null,
code: '42501',
message: 'permission denied for schema public'
}
Run Code Online (Sandbox Code Playgroud)
我认为这与我用来处理迁移的 Prisma 有关。当我只是浏览原型时,客户端工作得很好,但设置 Prisma 后,它就不再工作了。
对于如何解决这个问题,有任何的建议吗?我真的很希望能够同时使用 Supabase REST API 和 Prisma。
我遇到了一个问题,我需要通过用户名和电子邮件检查用户是否存在,因为两者都是数据库中的唯一字段,但我收到错误。
Argument where of type UserWhereUniqueInput needs exactly one argument, but you provided username and email. Please choose one.
那么,有没有办法只执行一次这个查询呢?而不是像下面这样为每个运行一个
const user = await prisma.user.findUnique({
where: {
username,
email,
},
});
Run Code Online (Sandbox Code Playgroud)
不是这样的
const user = await prisma.user.findUnique({
where: {
username,
},
});
const user = await prisma.user.findUnique({
where: {
email,
},
});
Run Code Online (Sandbox Code Playgroud) 大家好,我收到此错误“'prisma' 未被识别为内部或外部命令、可操作程序或批处理文件。” 在 cmd 中运行 prisma 登录命令时,我已使用npm install -g prisma 全局安装了 prisma任何解决方案将不胜感激。
我在 Prisma 中的模型关系并不那么简单。用户 --< 注册 >-- 课程,我不知道如何确保课程标题字段在该用户创建的课程中是唯一的。换句话说,我不希望一个用户创建多个具有相同名称的课程。但我希望不同的创建者以相同的名称存在课程。(只有创建者在注册中具有 TEACHER 角色)
我面临的问题是,我不知道在哪里定义唯一属性以及要包含哪些字段。我想要对其进行唯一约束的字段(课程名称、具有教师角色的成员)跨不同的模型。
model User {
id Int @id @default(autoincrement())
email String @unique
passwordHash String
enrollments Enrollment[]
}
model Course {
id Int @id @default(autoincrement())
name String
members Enrollment[]
}
model Enrollment {
role UserRole @default(STUDENT)
// Relation Fields
userId Int
courseId Int
user User @relation(fields: [userId], references: [id])
course Course @relation(fields: [courseId], references: [id])
@@id([userId, courseId])
@@index([userId, role])
}
Run Code Online (Sandbox Code Playgroud) 我的目标:我想在 GraphQL Playground 中执行一个变更。
我的架构如下所示:
type Mutation {
# Add a new comment
addComment(comment: InputComment!): Comment
}
# Input type for a new Comment
input InputComment {
# The comment text
comment: String!
# The id of the author
author: String!
# The id of the talk
talkId: Long!
}
Run Code Online (Sandbox Code Playgroud)
我发现了很多例子,如果我有:
type Mutation {
# Add a new comment
addComment(comment: String!, author: String!, talkId: Long!): Comment
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解如何InputComment在 GraphQL Playground 中动态创建类型对象。
例如,对于最后一个场景,我可以运行:
mutation {
addComment(
comment: "My …Run Code Online (Sandbox Code Playgroud) prisma-graphql ×10
prisma ×9
prisma2 ×3
graphql ×2
docker ×1
docker-api ×1
mysql ×1
next.js ×1
npm ×1
postgresql ×1
reactjs ×1
supabase ×1