Opened 13 years ago

Closed 13 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 Holovaty
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: no UI/UX: no


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 13 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

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

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