I have the following model:
class User(models.Model):
email = models.EmailField(max_length=254, null=False, unique=True)
referral_code = models.CharField(max_length=10, null=False, unique=True)
And used the Django shell to save a user instance with referral_code undefined:
u = User(email="test@example.com")
u.save()
This did not raise an exception. My understanding was that null=False would require referral_code to be set - Is this not the case? How would I achieve that behaviour?
update
I notice that the field is set to u.referral_code=''
, so given the uniqueness constraint, this has raised an exception when I tried to repeat the process with a new instance. I would rather the exception was thrown because I did not set the field...