Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否提供数据库呢方便搭建 #1

Open
mybre opened this issue Apr 5, 2022 · 13 comments
Open

能否提供数据库呢方便搭建 #1

mybre opened this issue Apr 5, 2022 · 13 comments

Comments

@mybre
Copy link

mybre commented Apr 5, 2022

No description provided.

@yuaanlin
Copy link
Member

yuaanlin commented Apr 5, 2022

@mybre 可以参考 教学文档 的方案,在 PlanetScale 平台申请一个免费的 MySQL 数据库 👍

Screen Shot 2022-04-05 at 21 11 30

@hichho
Copy link

hichho commented May 8, 2022

在执行npx prisma migrate dev --name init,一直提示没有权限创建databases

@yuaanlin
Copy link
Member

yuaanlin commented May 8, 2022

在执行npx prisma migrate dev --name init,一直提示没有权限创建databases

报错方便贴上来看一下吗

@hichho
Copy link

hichho commented May 8, 2022

在执行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
"

@yuaanlin
Copy link
Member

yuaanlin commented May 8, 2022

@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。

Screen Shot 2022-05-08 at 17 07 49

prisma/prisma#7292

@hichho
Copy link

hichho commented May 8, 2022

@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。

Screen Shot 2022-05-08 at 17 07 49

prisma/prisma#7292

issue
尝试过new branch ,deploy了生成password后npx run ... , 仍然有这个问题 ಥ_ಥ

@yuaanlin
Copy link
Member

yuaanlin commented May 8, 2022

@hichho 好像是 PlanetScale 权限设置的问题,不允许在 main 分支(这里指的是「数据库」的分支,PlanetScale 支持数据库维护多个分支)建立新数据库,可以试试在 PlanetScale 建立一个新分支,然后把 Prisma 的连接配置改为这个新分支。
Screen Shot 2022-05-08 at 17 07 49
prisma/prisma#7292

issue 尝试过new branch ,deploy了生成password后npx run ... , 仍然有这个问题 ಥ_ಥ

Screen Shot 2022-05-08 at 20 01 17

你是不是没有照配置把它放在 shadowDatabaseUrl 里面

@Xxxdxs
Copy link

Xxxdxs commented May 31, 2022

我也遇到了 这样直接过了
sudo npx prisma db push

@Akenokoru
Copy link

遇到

在执行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分支上

@silk9333
Copy link

silk9333 commented Aug 1, 2022

参考prisma issue#7292
设置了SHADOW_DATABASE_URL指向了测试分支,运行npx prisma migrate dev --name init还是谁出现 ( ERROR HY000 (1105): direct DDL is disabled)
如何在在非生产分支上执行 Prisma Migrate?

@kdaye
Copy link

kdaye commented Aug 8, 2022

我是这么过的.仅供参考.
.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

@LetHergo
Copy link

npx prisma db push

@birdmanmandbir
Copy link

可以改为用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?
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants