Ok, that sounds vague but I don't know how to better describe it. Basically it boils down to having this in models.py:
from django.db import models
import os
class c1(models.Model):
name = models.CharField("Name", max_length=30)
default_c1 = c1.objects.get(name="non_existant")
class c2(models.Model):
other = models.ForeignKey(c1, default=default_c1)
Querying c1 later with c1.objects.filter(c2pk=0) will fail:
FieldError?: Cannot resolve keyword 'c2' into field. Choices are: id, name
Minimal testcase project attached (models.py is slightly bigger than above). You can reproduce the problem with:
# Create the database (clobbers test.db in the current dir)
./manage.py syncdb
# See that without querying in between it works
echo -e "from proj1.app1.models import c1\nc1.objects.filter(c2__pk=0)" | ./manage.py shell
# See that with querying in between it fails
echo -e "from proj1.app1.models import c1\nc1.objects.filter(c2__pk=0)" | BREAK_ME=1 ./manage.py shell
Found on 1.0.2, confirmed with trunk (fresh checkout, less than 30 minutes ago)