Can anyone see the source of this error?
django.core.exceptions.FieldError: Cannot resolve keyword 'client' into field. Choices are: auditstatushistory, file_num, invoice
The statement that is causing the problem is:
for invoice in Invoice.objects.filter(matter__client__servicer_code = "XXX"):
And the definition of Matter, which does contain file_num, and auditstatushistory and invoice as related attributes, is :
class Matter(models.Model):
file_num = models.CharField(max_length=20, primary_key=True)
client = models.ForeignKey("Client", db_column="client_code",
related_name="client")
the only “odd” thing in here is that client did not exist as a foreign key when I set up the database originally, so I added client_code to the underlying matter table via
alter table foo_matter add client_code varchar(10) null;
And there is no foreign key in the database linking client and matter. The only thing I can think of is that I did not name the column correctly in my foo_matter table. But I can’t run syncdb to try it out because South has been installed.
UPDATE:
Just for giggles, I tried starting with a brand-new database, commented out South, and just did a “syncdb” to see what table definitions Django would create. It created the Client and Matter tables, but did NOT create client_code (or client_id) field to store the foreign key information.
Has anyone seen a situation like this, where Django just does not create a field?
Gaaah! The problem was that I had a property (with a getter) defined further down in the class named “client”. That was a leftover from an earlier iteration.