django can't resolve attribute name
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 a开发者_JAVA技巧s 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?
I'll take a wild guess, and say that the code you have right now and the fields in the database simply don't match. If you are not using south during development, the only way to make changes to the database is either by hand, or just dropping the changes tables and re-running syncdb. At the beginning of the design stage you can do that, but its really really recommended to use south, specially once you have data that you just can't drop.
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.
精彩评论