0

I am trying to build an application with django and graphene and I want to set a default value for one of the fields in my model. The mutation is really straight forward. I've passed all the required arguments as objects and the optional ones with **kwargs.

Django's docs on **options for models.UUIDField() says that if None type object is sent to the model field, default value will be used.

When I try to use my mutation without passing any values/ passing None as a value to the argument, I get graphql.error.located_error.GraphQLLocatedError: NOT NULL constraint failed: games_game.groupid error is raised.

Here is a pastebin for Tracebacks, models.py and schema.py to my project.

jdaz
  • 5,964
  • 2
  • 22
  • 34

1 Answers1

0

A developer from django made me regular constructor rules apply on django models as well!

here is a simple fix to my problem for anyone in the future.

    groupid = kwargs.get('groupid', None)
    gid_extra = {'groupid': groupid} if groupid else {}
    game = Game(name=name, price=price, datereleased=datereleased, 
    description=description, **gid_extra)
    game.save()