Opened 8 years ago

Closed 8 years ago

#5314 closed (invalid)

django.models.Manager.get and get_or_create Do Not Work With Null Fields

Reported by: cristian.esquivias@… Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Maybe this is a greater issue, but Django cannot find fields that are None.


from django.db import models

class Test(models.Model):
    title = models.CharField(max_length=30)
    description = models.CharField(max_length=200, null=True)

def test_run():
    # After running " syncdb"
    foo1, created = Test.objects.get_or_create(title='Foo', description=None)
    # created == True (good...)
    foo2, created = Test.objects.get_or_create(title='Foo', description=None)
    # created == True (that shouldn't be!)
    nrows = Test.objects.all().count()
    # nrows == 2

Django should be able able to search for None fields.

Change History (1)

comment:1 Changed 8 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Check the documentation. There is a difference between field=None and fieldisnull=True.

Note: See TracTickets for help on using tickets.
Back to Top