Skip to content

Instantly share code, notes, and snippets.

@amccloud
Created December 28, 2011 05:16
Show Gist options
  • Save amccloud/1526444 to your computer and use it in GitHub Desktop.
Save amccloud/1526444 to your computer and use it in GitHub Desktop.
from django.db import models
optional = dict(blank=True, null=True)
class Foo(models.Model):
bar = models.CharField()
baz = models.CharField(**optional)
@haplo
Copy link

haplo commented Dec 28, 2011

TextField and CharField (and other fields inheriting from CharField) shouldn't have null=True, because then you can store both a NULL and a blank string as the empty value, it's better to use only blank=True for those cases.

This is explained in the Django documentation: https://docs.djangoproject.com/en/1.3/ref/models/fields/#null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment