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

时间:2014-01-08 01:37:12

标签: python django unique django-south

我的用户类是:

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.')

我的尝试登录课程是:

class AccessAttempt( models.Model ):
    loginname = models.CharField('loginname', max_length=255)
    user=models.ForeignKey(PMUser, null=True, unique=True)
    failures = models.PositiveIntegerField( 'Failures', default=0 )
    timestamp = models.DateTimeField( 'Last failed attempt', null=True,auto_now=True )

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

 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定义为唯一键吗? 怎么解决呢?

0 个答案:

没有答案