添加用户报错,外键问题
来源:5-1 django admin介绍
小叶柏杉
2017-06-24
IntegrityError at /admin/users/userprofile/add/
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')
Request Method:
POST
Request URL:
http://127.0.0.1:8000/admin/users/userprofile/add/
Django Version:
1.9.8
Exception Type:
IntegrityError
Exception Value:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')
Exception Location:
C:\Users\gold\Envs\mxonline\lib\site-packages\MySQLdb\connections.py in defaulterrorhandler, line 36
Python Executable:
C:\Users\gold\Envs\mxonline\Scripts\python.exe
Python Version:
2.7.13
Python Path:
['E:\\MxOnline\\apps',
'E:\\MxOnline',
'E:\\MxOnline',
'E:\\MxOnline\\apps',
'C:\\Windows\\system32\\python27.zip',
'C:\\Users\\gold\\Envs\\mxonline\\DLLs',
'C:\\Users\\gold\\Envs\\mxonline\\lib',
'C:\\Users\\gold\\Envs\\mxonline\\lib\\plat-win',
'C:\\Users\\gold\\Envs\\mxonline\\lib\\lib-tk',
'C:\\Users\\gold\\Envs\\mxonline\\Scripts',
'c:\\python27\\Lib',
'c:\\python27\\DLLs',
'c:\\python27\\Lib\\lib-tk',
'C:\\Users\\gold\\Envs\\mxonline',
'C:\\Users\\gold\\Envs\\mxonline\\lib\\site-packages']
Server time:
星期六, 24 六月 2017 18:49:28 +0800
class UserProfile(AbstractUser): nick_name = models.CharField(max_length=50, verbose_name=u'昵称', default='') birday = models.DateField(verbose_name=u'生日', null=True, blank=True) gender = models.CharField(max_length=6, choices=(('male', u'男'), ('female', u'女')), default='male', verbose_name=u"性别") address = models.CharField(max_length=100, default=u'', verbose_name=u"地址") mobile = models.CharField(max_length=11, null=True, blank=True, verbose_name=u"手机号") image = models.ImageField(upload_to="image/%Y/%m", default=u"image/default.png", max_length=100, verbose_name=u"头像") class Meta: verbose_name="用户信息" verbose_name_plural = verbose_name def __unicode__(self): return self.username
莫名的报错了,说我的外键的问题,不知道是那啊,按照老师的代码敲的啊
2回答
-
先不着急添加用户 后面将admin切换为xadmin后 这个问题就没有了
132017-07-03 -
网络侦探
2017-08-11
00
相似问题