diff --git a/tests/bug23940/__init__.py b/tests/bug23940/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/bug23940/models.py b/tests/bug23940/models.py
new file mode 100644
index 0000000..644a613
--- /dev/null
+++ b/tests/bug23940/models.py
@@ -0,0 +1,9 @@
+from django.db import models
+
+class Foo(models.Model):
+    # Changing the name of this field to anything else makes the test pass
+    exact = models.BooleanField(default=False)
+
+
+class Bar(models.Model):
+    foo = models.ForeignKey('Foo')
diff --git a/tests/bug23940/tests.py b/tests/bug23940/tests.py
new file mode 100644
index 0000000..8efe68a
--- /dev/null
+++ b/tests/bug23940/tests.py
@@ -0,0 +1,9 @@
+from django.test import TestCase
+
+from .models import Foo, Bar
+
+class FooTestCase(TestCase):
+    def test_foo(self):
+        f = Foo.objects.create()
+        b = Bar.objects.create(foo=f)
+        self.assertEqual(f.bar_set.count(), 1)
