无法创建超级用户Django [英] Can't Create Super User Django
问题描述
我的模型看起来像是从django.contrib.auth.models的django.db导入模型
从django.db.models.signals导入用户
import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User)#required
location = models.CharField(max_length = 100)
age = models.PositiveIntegerField(blank = True,null = True)
contribution_points = models.PositiveIntegerField()
#acheivements = models.ManyToMany )
def create_user_profile(发件人,实例,创建,** kwargs):
如果创建:
UserProfile.objects.create(user = instance)
post_save.connect(create_user_profile,sender = User)
但是,最后我出现以下错误:
django.db.utils.DatabaseError:(1146,Tablesavory_db.login_userprofile不存在)
尽管刚刚运行 syncdb
我的模型是否有任何矛盾的字段会导致此错误。 UserProfile是否应用于超级用户?我应该如何防止这种情况?
在2011年3月23日上午4:25,马尔科姆·马丁写道: >
进一步的调查:看起来像是一个南/ syncdb交互。
UserProfile将由南方迁移创建,但当然,当auth post_install运行时,
没有运行,以提示超级用户。
可悲的是,syncdb --migrate也没有做正确的事情。
现在,我只是使用./manage.py $ b手动创建一个超级用户$ b shell,但欢迎任何关于如何更好地解决这个问题的想法。
在syncdb期间不要创建超级用户,你用户配置文件表将不存在。
您必须在管理员上创建一个创建用户个人资料的信号,看起来像
,因为它是失败的
您要使用的过程初始化数据库是:
python manage.py syncdb --noinput
python manage.py migrate
python manage.py createduperuser
参考:https://groups.google.com/forum/?fromgroups=#!topic/django-users/sBXllxrIdMc
I'm assuming that it is because my superuser depends on UserProfile which has no existing data yet. My model looks like
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User) # required
location = models.CharField(max_length=100)
age = models.PositiveIntegerField(blank=True,null=True)
contribution_points = models.PositiveIntegerField()
#acheivements = models.ManyToMany()
def create_user_profile(sender,instance,created,**kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
However, I end up with the following error:
django.db.utils.DatabaseError: (1146, "Table 'savory_db.login_userprofile' doesn't exist")
despite having just ran syncdb
Does my model have any contradictory fields that would cause this error. Should UserProfile not be applied to the superuser? How should I prevent this?
On Mar 23, 2011, at 4:25 AM, Malcolm Box wrote:
Further investigation: looks like it's a South/syncdb interaction. The UserProfile will be created by the south migration, but of course that hasn't run when the auth post_install runs to prompt for a superuser.
Sadly syncdb --migrate doesn't do the right thing either.
For now, I'm just creating a superuser manually using ./manage.py shell, but would welcome any ideas on how to solve this better.
Don't create the super user during syncdb, you user profile table will not exist. You must have a create signal on admin that creates a user profile, this looks like it is failing
The procedure you wan to use to initialize the database is:
python manage.py syncdb --noinput
python manage.py migrate
python manage.py createsuperuser
Reference : https://groups.google.com/forum/?fromgroups=#!topic/django-users/sBXllxrIdMc
这篇关于无法创建超级用户Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!