I've ran this command for the T3 boilerplate: npm create t3-app@latest
我已经为T3样板运行了以下命令:npm create T3-app@Latest
I then added only the bcrypt and fakerjs library for my prisma seed:
然后,我只为我的Prisma种子添加了bcrypt和fakerjs库:
{
"name": "priority",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.5",
"@prisma/client": "^4.14.0",
"@t3-oss/env-nextjs": "^0.3.1",
"@tanstack/react-query": "^4.29.7",
"@trpc/client": "^10.26.0",
"@trpc/next": "^10.26.0",
"@trpc/react-query": "^10.26.0",
"@trpc/server": "^10.26.0",
"bcrypt": "^5.1.0",
"next": "^13.4.2",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",
"@types/bcrypt": "^5.0.0",
"@types/eslint": "^8.37.0",
"@types/node": "^18.16.0",
"@types/prettier": "^2.7.2",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"autoprefixer": "^10.4.14",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"prisma": "^4.14.0",
"tailwindcss": "^3.3.0",
"typescript": "^5.1.3"
},
"ct3aMetadata": {
"initVersion": "7.13.2"
}
}
I created my seed file inside my prisma dir:
我在Prisma目录中创建了种子文件:
import { PrismaClient } from "@prisma/client";
import { faker } from "@faker-js/faker";
import bcrypt, { hash } from "bcrypt";
import { type Deadline, Priority } from "../src/types/types";
const prisma = new PrismaClient();
const deadlines: Deadline[] = Array.from({ length: 100 }, () => ({
title: faker.lorem.sentences({ min: 10, max: 20 }),
description: faker.lorem.sentences({ min: 3, max: 30 }),
date: faker.date.future({ years: 1 }),
priority: faker.helpers.enumValue(Priority),
}));
async function main() {
const hashedPassword = await bcrypt.hash("Matt123$", 12);
const user = await prisma.user.create({
data: {
name: "Matt",
email: "[email protected]",
hashedPassword,
},
});
const data = deadlines.map((deadline) => {
return { ...deadline, userId: user.id };
});
await prisma.deadline.createMany({
data,
});
}
main()
.then(async () => {
console.log("seeded!");
await prisma.$disconnect();
})
.catch((e) => {
console.log(e);
process.exit(1);
});
And defined my schema:
并定义了我的方案:
// 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 = "mongodb"
// NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}
enum Priority {
HIGH
MEDIUM
LOW
}
model Deadline {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
description String?
date DateTime
priority Priority
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
// Necessary for Next auth
model Account {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(auto()) @map("_id") @db.ObjectId
sessionToken String @unique
userId String @db.ObjectId
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
hashedPassword String?
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
deadlines Deadline[]
}
model VerificationToken {
id String @id @default(auto()) @map("_id") @db.ObjectId
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
These are the only steps I've taken and yet I'm still getting the following error on my createMany method:
这些是我采取的唯一步骤,但我的createMany方法仍然出现以下错误:
Unsafe member access .createMany on an `any` value.eslint@typescript-eslint/no-unsafe-member-access
Unsafe call of an `any` typed value.eslint@typescript-eslint/no-unsafe-call
(method) Prisma.DeadlineDelegate<Prisma.RejectOnNotFound | Prisma.RejectPerOperation | undefined>.createMany<{
data: {
userId: string;
title: string;
description?: string | undefined;
priority: Priority;
date: Date;
}[];
}>(args?: {
data: {
userId: string;
title: string;
description?: string | undefined;
priority: Priority;
date: Date;
}[];
} | undefined): Prisma.PrismaPromise<...>
Create many Deadlines.
@param args — Arguments to create many Deadlines.
@example
// Create many Deadlines
const deadline = await prisma.deadline.createMany({
data: {
// ... provide data here
}
})
I have no clue what's going on, I've deleted and reinstalled the app like 3 times and I've been at this for atleast an hour.
我不知道发生了什么,我已经删除并重新安装了这款应用程序大约3次,我已经这样做了至少一个小时。
Here's my tsconfig, figured it might help somehow even though I didnt touch it:
这是我的tsconfig,我想它可能会有所帮助,尽管我没有碰它:
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
}
},
"include": [
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs"
],
"exclude": ["node_modules"]
}
更多回答
我是一名优秀的程序员,十分优秀!