Prisma迁移无法工作,因为模式不为空,但模式是空的(错误P3005)。

huangapple go评论67阅读模式
英文:

Prisma migrate not working due to schema not empty, but schema is empty (error P3005)

问题

我想测试一下 Prisma,因为我以前从未使用过它。

最初的迁移成功了,但我现在无法对模式进行更改。

我是否误解了 Prisma 迁移的工作原理?

我创建了一个简单的 Prisma 模式:

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

datasource db {
  provider          = "postgresql"
  url               = env("POSTGRES_PRISMA_URL")
  directUrl         = env("POSTGRES_URL_NON_POOLING")
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
}

然后运行了 prisma migrate dev --name init,成功设置了我的数据库模式。

现在我对模式进行了更改,我向 User 模型添加了一个新的列:

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
  username String
}

运行 prisma migrate dev --name add_username 失败,并显示以下错误:

Error: P3005

The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline

我做错了什么?

英文:

I wanted to test out prisma, as I have never used it before.

The inital migration was succesfull, but I am unable to make changes to the schema now.

Am I misunderstanding how prisma migrations are supposed to work?

What I did is create a simple prisma schema:

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

datasource db {
  provider          = "postgresql"
  url               = env("POSTGRES_PRISMA_URL")
  directUrl         = env("POSTGRES_URL_NON_POOLING")
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
}

And then ran prisma migrate dev --name init, which successfully setup my DB schema.

Now I made changes to the schema, I added one new column to the User model:

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
  username String
}

Running prisma migrate dev --name add_username fails with the error:

Error: P3005

The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline

What am I doing wrong?

答案1

得分: 0

It seems it is an issue by the host (vercel in my case)

See this

英文:

As it seems it is an issue by the host (vercel in my case)

See this

huangapple
  • 本文由 发表于 2023年5月14日 00:41:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定