Prohibit model instance with null attribute in Django
I start with this:
from django.db import models
class Example(models.Model):
id = models.Charfield(null=False)
name = models.Charfield(null=False)
Now if I create a new object with a name and without an id, the id will be
replaced with an empty string and the object creation will be successful.
I would like it to return an error instead since I specified null=False.
Is there a "native" way to do it?
example = Example.objects.create(name="test")
No comments:
Post a Comment