在 Prisma Client 中如何在没有 'NULL values' 的情况下进行迁移

How can I Migrate without 'NULL values' in Prisma Client

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

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.

您收到此错误是因为您试图使一个可选列成为必需列,而数据库中的数据对这些列具有空值。您可以 运行 npx prisma migrate dev --create-only 创建迁移文件。在迁移文件中,您将不得不编写一些额外的内容 sql,或者向缺失数据的记录添加数据,或者删除缺失数据的记录。