megusta
PPrisma
•Created by megusta on 1/20/2025 in #help-and-questions
Nullable unique field on Prisma
Hi, @everyone, I have a Prisma model on MongoDB.
the stakeId field is nullable field.
Now I can't run
model StakeTx {
txId String @id @map("_id")
stakeId String? @unique @db.ObjectId
sourceAddress String
targetAddress String
amount Int
fee Int
confirmed Boolean @default(false)
createdAt DateTime?
stake Stake? @relation(fields: [stakeId], references: [id])
unstake Unstake?
@@index([txId, stakeId])
@@index([sourceAddress, targetAddress])
@@index([confirmed])
@@map("stake_txs")
}
model StakeTx {
txId String @id @map("_id")
stakeId String? @unique @db.ObjectId
sourceAddress String
targetAddress String
amount Int
fee Int
confirmed Boolean @default(false)
createdAt DateTime?
stake Stake? @relation(fields: [stakeId], references: [id])
unstake Unstake?
@@index([txId, stakeId])
@@index([sourceAddress, targetAddress])
@@index([confirmed])
@@map("stake_txs")
}
yarn prisma db push
I got this error
Kind: Command failed: Error code 11000 (DuplicateKey): Index build failed: 40f377f5-628e-4e6a-8439-4297d00661ca: Collection pivotal_db_staging.stake_txs ( c5460ee6-0849-45d0-8176-410b24afb3e3 ) :: caused by :: E11000 duplicate key error collection: pivotal_db_staging.stake_txs index: stake_txs_stakeId_key dup key: { stakeId: null }, labels: {}
Kind: Command failed: Error code 11000 (DuplicateKey): Index build failed: 40f377f5-628e-4e6a-8439-4297d00661ca: Collection pivotal_db_staging.stake_txs ( c5460ee6-0849-45d0-8176-410b24afb3e3 ) :: caused by :: E11000 duplicate key error collection: pivotal_db_staging.stake_txs index: stake_txs_stakeId_key dup key: { stakeId: null }, labels: {}
4 replies