Opened 18 years ago
Closed 18 years ago
#5314 closed (invalid)
django.models.Manager.get and get_or_create Do Not Work With Null Fields
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| 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 |
Description
Maybe this is a greater issue, but Django cannot find fields that are None.
Example:
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 "manage.py 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.
Note:
See TracTickets
for help on using tickets.
Check the documentation. There is a difference between field=None and fieldisnull=True.