为什么我的Django south不能迁移,因为没有唯一的约束匹配?

2024-06-28 19:20:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我的用户类是:

class PMUser(models.Model):

   username = models.CharField(max_length=30, help_text='Required. Maximum 30 characters.')
   firstname = models.CharField(max_length=30, help_text='Enter first name.')
   lastname = models.CharField(max_length=30, help_text='Enter last name.')
   contactnumber = models.CharField(max_length=30, blank=True, help_text='Telephone number or mobile number.')
   email = models.EmailField(unique=True,help_text='Enter email address.')

我的attemptlogin类是:

^{pr2}$

当我尝试使用Django South来构建新的accessTry表时:

 C:\workspace\pmode>python manage.py schemamigration pmauth --auto
 + Added field user on pmauth.AccessAttempt
 Created 0003_auto__add_field_accessattempt_user.py. You can now apply this migra
 tion with: ./manage.py migrate pmauth

 C:\workspace\pmode>python manage.py migrate pmauth
 Running migrations for pmauth:
 - Migrating forwards to 0003_auto__add_field_accessattempt_user.
 > pmauth:0003_auto__add_field_accessattempt_user
 FATAL ERROR - The following SQL query failed: ALTER TABLE "auth_accessattempt" A
 DD CONSTRAINT "user_id_refs_id_9d1b56dc" FOREIGN KEY ("user_id") REFERENCES "aut
 h_pmuser" ("id") DEFERRABLE INITIALLY DEFERRED;
 The error was: there is no unique constraint matching given keys for referenced
 table "auth_pmuser"

 Error in migration: pmauth:0003_auto__add_field_accessattempt_user
 DatabaseError: there is no unique constraint matching given keys for referenced
 table "auth_pmuser"

问题是我还没有在表(类)PMUser中将user_id定义为unique key? 如何解决?在


Tags: textpyaddidfieldautomodelshelp