[1.10.x] Refs #26983 -- Added test for isnull lookup to CharField with primary_key=True.
Backport of 97513269d7
from master
This commit is contained in:
parent
04f0c2ab39
commit
c24a47b3e6
|
@ -28,7 +28,8 @@ Bugfixes
|
|||
(:ticket:`27005`).
|
||||
|
||||
* Fixed the ``isnull`` lookup on a ``ForeignKey`` with its ``to_field``
|
||||
pointing to a ``CharField`` (:ticket:`26983`).
|
||||
pointing to a ``CharField`` or pointing to a ``CharField`` defined with
|
||||
``primary_key=True`` (:ticket:`26983`).
|
||||
|
||||
* Prevented the ``migrate`` command from raising
|
||||
``InconsistentMigrationHistory`` in the presence of unapplied squashed
|
||||
|
|
|
@ -261,7 +261,7 @@ class CustomPk(models.Model):
|
|||
|
||||
|
||||
class Related(models.Model):
|
||||
custom = models.ForeignKey(CustomPk, models.CASCADE)
|
||||
custom = models.ForeignKey(CustomPk, models.CASCADE, null=True)
|
||||
|
||||
|
||||
class CustomPkTag(models.Model):
|
||||
|
|
|
@ -2483,7 +2483,16 @@ class ToFieldTests(TestCase):
|
|||
[node1]
|
||||
)
|
||||
|
||||
def test_isnull_query(self):
|
||||
|
||||
class IsNullTests(TestCase):
|
||||
def test_primary_key(self):
|
||||
custom = CustomPk.objects.create(name='pk')
|
||||
null = Related.objects.create()
|
||||
notnull = Related.objects.create(custom=custom)
|
||||
self.assertSequenceEqual(Related.objects.filter(custom__isnull=False), [notnull])
|
||||
self.assertSequenceEqual(Related.objects.filter(custom__isnull=True), [null])
|
||||
|
||||
def test_to_field(self):
|
||||
apple = Food.objects.create(name="apple")
|
||||
Eaten.objects.create(food=apple, meal="lunch")
|
||||
Eaten.objects.create(meal="lunch")
|
||||
|
|
Loading…
Reference in New Issue