我的models.py包含一个包含两个外键的模型:
class TestcaseHasCategory(models.Model):
testcase_idtestcase = models.ForeignKey(Testcase, models.DO_NOTHING, db_column='Testcase_idTestcase') # Field name made lowercase.
Category_idCategory = models.ForeignKey(Category, models.DO_NOTHING, db_column='Category_idCategory') # Field name made lowercase.
class Meta:
managed = False
db_table = 'testcase_has_category'
unique_together = (('testcase_idtestcase', 'Category_idCategory'),)
在Django shell打印中,该表的对象为我提供了这个输出:
>>> TestcaseHasCategory.objects.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 232, in _
_repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 256, in _
_iter__
self._fetch_all()
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 1087, in
_fetch_all
self._result_cache = list(self.iterator())
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 54, in __
iter__
results = compiler.execute_sql()
File "c:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 83
5, in execute_sql
cursor.execute(sql, params)
File "c:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in
execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "c:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
File "c:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in
execute
return self.cursor.execute(sql, params)
File "c:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 11
0, in execute
return self.cursor.execute(query, args)
File "c:\Python27\lib\site-packages\MySQLdb\cursors.py", line 202, in execute
self.errorhandler(self, exc, value)
File "c:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defau
lterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'testcase_has_category.id' in 'fiel
d list'")
我的其他模型是可打印的,只有多对多的关系才会产生问题。有什么想法吗?