gpt4 book ai didi

mysql - EPERM : operation not permitted error : Prisma . 输入命令后 'npx migrate dev --name init'

转载 作者:行者123 更新时间:2023-12-03 08:09:53 24 4
gpt4 key购买 nike

我正在尝试运行 Prisma 以使用 Node js 服务器与 MySQL 数据库集成。将 Prisma 架构迁移到 MySql 数据库后,我在 Mac air m1 上收到以下错误我已经验证数据库 URL 配置正确。我尝试过强制清除缓存,重新安装npm,重新启动电脑,然后重新启动VsCode。

EPERM:不允许操作,utime '/Users/apple/.cache/prisma/master/bcc2ff906db47790ee902e7bbc76d7ffb1893009/darwin-arm64/prisma-fmt'apple@Apples-MacBook-Air 服务器%

当我尝试运行 server.js 文件时,出现以下错误

@prisma/client 尚未初始化。请运行“prismagenerate”并尝试再次导入。如果您意外出现此错误,请在 https://github.com/prisma/prisma/issues 中报告。在新的 PrismaClient (/Users/apple/Desktop/react-i/servers/node_modules/.prisma/client/index.js:3:11)在对象。 (/Users/apple/Desktop/react-i/servers/authenticate.js:7:16)在Module._compile( Node :内部/模块/cjs/loader:1101:14)在 Object.Module._extensions..js ( Node :内部/模块/cjs/loader:1153:10)在Module.load( Node :内部/模块/cjs/loader:981:32)在 Function.Module._load ( Node :内部/模块/cjs/loader:822:12)在 Module.require ( Node :内部/模块/cjs/loader:1005:19)在需要时( Node :内部/模块/cjs/helpers:102:18)在对象。 (/Users/apple/Desktop/react-i/servers/server.js:7:18)在Module._compile( Node :内部/模块/cjs/loader:1101:14)

运行npx prismagenerate再次出现第一个错误

感谢任何帮助

这是相关的服务器代码片段

const { PrismaClient } = require("@prisma/client");
const crypto = require('crypto');
const express = require('express');
const route = express.Router();
const jwt = require('jsonwebtoken');
const prisma = new PrismaClient();
const addUserToDb = async user => {
try {
const newUser = await prisma.users.create({
data: {
email: user.email,
username: user.username,
password: hashPassword(user.password),
isAdmin: true,
},
});
console.log(JSON.stringify(newUser));
} catch (e) {
console.error(e);
return 'problem adding user to db';
}
return 'user added to db';
};

const hashPassword = password => {
let salt = crypto.randomBytes(16).toString('hex');
hashedpwd = crypto.pbkdf2Sync(password, salt, 1000, 64, 'sha512');
console.log(hashedpwd);
return hashedpwd;
};
const generateToken = (user, time = '300s') =>
jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, { expiresIn: time });

route.post('/register', (req, res) => {
let newUser = req.body.userRegister;

const accessToken = jwt.sign(newUser, process.env.ACCESS_TOKEN_SECRET);
res.json({ user: addUserToDb(newUser), token: accessToken });
});

module.exports = route;

//prisma.schema code

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

model Users {
id String @id @default(uuid())
username String @unique @db.VarChar(255)
email String? @unique @db.VarChar(255)
password String @db.VarChar(255)
refreshToken String?
passwordResetToken String?
profileImgUrl String?
customers Customers?
role String @default("user")

@@map(name: "users")
}

model Services {
id Int @id @default(autoincrement())
orders Orders[]
title String
description String
SAC String? @unique @db.VarChar(255)

@@map(name: "services")
}

model Customers {
customers Users @relation(fields: [customerId], references: [id])
customerId String @unique
firstName String
lastName String
phoneNumber Int
address String
State String
Pincode Int
City String?
orders Orders[]

@@map(name: "customers")
}

model Orders {
id Int @id @default(autoincrement())
value Float
createdAt DateTime @default(now())
service Services @relation(fields: [serviceId], references: [id])
serviceId Int
customer Customers @relation(fields: [customerId], references: [customerId])
customerId String

@@map(name: "orders")
}

model Reviews {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
starRating Int
content String?

@@map(name: "reviews")
}

最佳答案

删除此目录下缓存的 Prisma 文件夹 /Users/<your_apple_username>/.cache/并重新初始化 Prisma 以使其再次工作

关于mysql - EPERM : operation not permitted error : Prisma . 输入命令后 'npx migrate dev --name init',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71140478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com