prisma内省生成无效的模型



Prisma版本:^2.26.0

Prisma/客户:^2.26.0

@关系错误消息in:分析属性时出错"关系":模型posts中的字段userId的类型与模型users中的引用字段id的类型不匹配。


为什么在我运行npx prisma内省后,prisma创建了无效的模型或我的代码出现了问题?

这导致无法进入prisma工作室,因为我的代码中有这些错误。

有什么解决方案或想法可以分享,让我更好地了解这一点吗?

下面是我的sql:

-- Create a custom type
CREATE TYPE "user_role_enum" AS ENUM ('user', 'admin', 'superadmin');
-- Create a table
CREATE TABLE "users"(
"id" BIGSERIAL PRIMARY KEY NOT NULL,
"name" VARCHAR(255) NOT NULL,
"email" VARCHAR(255) UNIQUE NOT NULL,
"role" user_role_enum NOT NULL DEFAULT('user')
);
-- Create a table
CREATE TABLE "posts"(
"id" BIGSERIAL PRIMARY KEY NOT NULL,
"title" VARCHAR(255) NOT NULL,
"body" TEXT,
"userId" INTEGER NOT NULL,
FOREIGN KEY ("userId") REFERENCES "users"("id")
);
-- Create data
INSERT INTO "users" ("name", "email", "role")
VALUES('John Doe', 'john@email.com', 'admin'),
('jane Doe', 'jane@email.com', 'admin'),
('Ahmed Hadjou', 'ahmed@hadjou.com', 'user');
INSERT INTO "posts" ("title", "body", "userId")
VALUES('Hello World!!', 'Hey guys, I see a rainbow through this prisma :D', 1),
('So do I', 'It looks cooool!!!', 2),
('It does', 'Yeahhh', 1);

从棱镜内省生成模型


model posts {
id     BigInt  @id @default(autoincrement())
title  String  @db.VarChar(255)
body   String?
userId Int
users  users   @relation(fields: [userId], references: [id]) // Error parsing attribute "@relation": The type of the field `userId` in the model `posts` is not matching the type of the referenced field `id` in model `users`.
}
model users {
id    BigInt         @id @default(autoincrement())
name  String         @db.VarChar(255)
email String         @unique @db.VarChar(255)
role  user_role_enum @default(user)
posts posts[] // error in here
}
enum user_role_enum {
user
admin
superadmin
}

只需在Post Model中将Int更改为BigInt userId,它就会在中工作

最新更新