prisma / prisma1

💾 Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB) [deprecated]
https://v1.prisma.io/docs/
Apache License 2.0
16.55k stars 862 forks source link

Unable to set null on unique field #4858

Closed itsluke closed 5 years ago

itsluke commented 5 years ago

Describe the bug I am unable to set a unique field to null in a mutation.

To Reproduce Steps to reproduce the behavior:

  1. Create a database type with a @unique constraint
  2. Create an object with that field explicitly set to null
  3. Create another object with the same field explicitly set to null
  4. See error

error

...
"message": "A unique constraint would be violated on User. Details: Field name = email"
...

datamodel.prisma

type User {
    id: ID! @id
    createdAt: DateTime! @createdAt
    updatedAt: DateTime! @updatedAt
    email: String @unique
}

docker-compose.yml

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.34
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: mongo
            uri: 'mongodb://prisma:prisma@mongo'
  mongo:
    image: mongo:3.6
    restart: always
    # Uncomment the next two lines to connect to your your database from outside the Docker environment, e.g. using a database GUI like Compass
    # ports:
    # - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: prisma
      MONGO_INITDB_ROOT_PASSWORD: prisma
    volumes:
      - mongo:/var/lib/mongo
volumes:
  mongo:

Expected behavior As mentioned in the documentation "The only exception is the null value, meaning that multiple nodes can have the value null without violating the constraint."

However, when null is set explicitly to multiple objects it violates the unique constraint

Versions (please complete the following information):

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.