帶PostgreSQL的Django 1.11。表「app_employee」的多個主鍵是不允許的。
我去遷移我的網站和models.py
引發錯誤,我不能有多個主鍵。我看不到我在哪裏(或者我不瞭解如何)。
class Employee(models.Model):
Aegis_ID = models.UUIDField(primary_key=True, null=False, default=uuid.uuid4, editable=False, serialize=True)
Employee_Number = models.ForeignKey('self', on_delete=models.CASCADE, related_name='Company_Employee_Number',
null=True, blank=True, max_length=6, help_text="Employee ID")
Employee_FName = models.CharField(null=True, blank=True, max_length=25, help_text="First Name")
Employee_LName = models.CharField(null=True, blank=True, max_length=25, help_text="Last Name")
Employee_Email = models.EmailField(max_length=80, blank=True, help_text="GPM Email address")
Employee_Position = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True,
related_name='Department_Employee_Position', max_length=3,
choices=EMPLOYEE_POSITION, help_text="Select position of this Employee.")
Hire_Date = models.DateField(null=True, blank=True, help_text="Enter the employee hire date.")
Employee_Division = models.CharField(max_length=2, null=True, blank=True, choices=DIVISION_CHOICES,
help_text="Assign the Audit Division for this employee.")
Employee_Region = models.CharField(max_length=3, null=True, blank=True, choices=REGION_CHOICES,
help_text="Assign the Audit Region for this employee.")
Employee_District = models.CharField(max_length=3, null=True, blank=True, choices=DISTRICT_CHOICES,
help_text="Assign the Audit District for this Employee.")
閱讀這個確切主題Django的頁面,它的上市爲1.7解決的問題,不得不做Django是如何分類的類的表,按字母順序。
我也試過python manage.py flush
隨後makemigrations
之前migrate
那麼,哪些字段是Django的/的Postgres試圖進行「ID」和「主」,因爲我只是不理解,在這裏.. 。
根據關於自動主鍵Django文檔,還有看不見的是id = models.AutoField(primary_key=True)
但我也明白,如果您分配primary_key=True
到現場,這並不適用