Open mybre opened 2 years ago
在执行npx prisma migrate dev --name init,一直提示没有权限创建databases
在执行npx prisma migrate dev --name init,一直提示没有权限创建databases
报错方便贴上来看一下吗
在执行npx prisma migrate dev --name init,一直提示没有权限创建databases
报错方便贴上来看一下吗 "Datasource "db": MySQL database "blog" at "g5z8l8lhcs3q.ap-southeast-2.psdb.cloud:3306"
Error: P3014
Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases. Read more about the shadow database (and workarounds) at https://pris.ly/d/migrate-shadow
Original error: create database is not supported 0: migration_core::state::DevDiagnostic at migration-engine\core\src\state.rs:250 "
@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。
@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。
尝试过new branch ,deploy了生成password后npx run ... , 仍然有这个问题 ಥ_ಥ
@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。
尝试过new branch ,deploy了生成password后npx run ... , 仍然有这个问题 ಥ_ಥ
你是不是没有照配置把它放在 shadowDatabaseUrl
里面
我也遇到了 这样直接过了 sudo npx prisma db push
遇到
在执行npx prisma migrate dev --name init,一直提示没有权限创建databases
使用PlanetScale时需要基于main创建出另外一个分支作为shadow database,然后把对应的分支密码配置到相关文件里(schema.prisma, .env)。 后续如果还遇到P3022报错的话,是因为PlanetScale 不允许在数据库 ( ERROR HY000 (1105): direct DDL is disabled) 的生产分支上更改架构,只能在非生产分支上执行 Prisma Migrate,然后使用 PlanetScale“部署请求”将架构更改合并到main分支上
参考prisma issue#7292
设置了SHADOW_DATABASE_URL指向了测试分支,运行npx prisma migrate dev --name init
还是谁出现 ( ERROR HY000 (1105): direct DDL is disabled)
如何在在非生产分支上执行 Prisma Migrate?
我是这么过的.仅供参考.
在.env
里
DATABASE_URL='new branch link'
SHADOW_URL='main link'
在prisma/scheme.prisma
里
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "mysql"
referentialIntegrity = "prisma"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_URL")
}
然后npx prisma migrate dev --name init
$ npx prisma migrate dev --name init
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "blog" at "xxxx:3306"
Applying migration `20220808030235_init`
The following migration(s) have been created and applied from new schema changes:
migrations/
└─ 20220808030235_init/
└─ migration.sql
Your database is now in sync with your schema.
✔ Generated Prisma Client (4.1.1 | library) to .\node_modules\@prisma\client in 52ms
npx prisma db push
可以改为用mongodb atlas, 稍微改下scheme.prisma即可
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "mongodb"
referentialIntegrity = "prisma"
url = env("DATABASE_URL")
}
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
imageUrl String?
tags String
@@index(authorId)
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
passwordHash String
name String?
posts Post[]
avatarUrl String?
}
@mybre 可以参考 教学文档 的方案,在 PlanetScale 平台申请一个免费的 MySQL 数据库 👍