我有一个遗留数据库,它有一个存储多对多关系的表,但没有一个主键列。有没有办法说服Django使用它呢?
示意性:
Product 1<---->* Labeling *<---->1 LabelDjango表使用(product_id,label_id)作为复合主键,我看不到任何方法来通知Labeling这一点。(仅仅使用through就可以得到Unknown column 'labeling.id' in 'field list'。)
是否需要回退到自定义SQL?还是我错过了什么?
发布于 2015-07-31 16:28:52
如果将unique_together添加到多对多表的模型中,Django将使用这些列,而不需要名为id的主键。
发布于 2010-06-22 17:36:40
希望这能帮到你,
http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.db_index
https://stackoverflow.com/questions/3091665
复制相似问题