【问题标题】:How can I Migrate without 'NULL values' in Prisma Client如何在 Prisma Client 中没有“NULL 值”的情况下进行迁移
【发布时间】:2022-01-21 10:28:46
【问题描述】:

大家好,你能帮我解决这个问题吗,即使在运行 npx prisma generatenpx prisma migrate dev 之后,我也会收到一个“无法执行”的错误。如果问号“?”被删除,我尝试“迁移”我得到的错误如下:

model Creative {
  id             Int      @id @default(autoincrement())
  stock_id       String   @default(cuid())
  parent_id      String   @default(cuid())
  hostelMenu     String?
  inStock        String?

}

//Error:
:warning: We found changes that cannot be executed:

  • Step 0 Made the column `hostelMenu` on table `Creative` required, but there are 1 existing NULL values.
  • Step 0 Made the column `inStock` on table `Creative` required, but there are 1 existing NULL values.

You can use prisma migrate dev --create-only to create the migration file, and manually modify it to address the underlying issue(s).
Then run prisma migrate dev to apply it and verify it works.

【问题讨论】:

    标签: prisma prisma2


    【解决方案1】:

    您收到此错误是因为您尝试将可选列设为必需,并且数据库中的数据对这些列具有空值。您可以运行npx prisma migrate dev --create-only 来创建迁移文件。在迁移文件中,您将不得不编写一些额外的 sql,将数据添加到丢失数据的记录或删除丢失数据的记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2021-10-22
      相关资源
      最近更新 更多