0
我定義了兩個模型在Django的模型文件:OneToOneField字段的字段名稱是追加`_id`變量名後
class Personnel(models.Model):
personnel_id = models.IntegerField(primary_key=True)
#...
class Settlement(models.Model):
personnel_id = models.OneToOneField(Personnel, primary_key=True)
#...
運行python manage.py makemigratios app_name
後,我檢查了創建表的SQL:
CREATE TABLE settlement (`personnel_id_id` integer NOT NULL PRIMARY KEY, ...
爲什麼實際的字段名稱是personnel_id_id
insend personnel_id
?
這是否意味着我應該將該字段命名爲'personnel'而不是'personnel_id'? – stamaimer
是的..這會幫你照顧它。就在您輸入評論時,我正在編輯答案:) – karthikr