无法在syncdb之后创建超级用户 [英] unable to create superuser after syncdb

查看:106
本文介绍了无法在syncdb之后创建超级用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢django和web开发。在创建超级用户时,从Django的最终指南中学习,我收到以下错误(OS mac10.8.2& django1.4.3)

 <$ c $你想现在创建一个? (是/否):是
追溯(最近的最后一次调用):
文件manage.py,第10行在< module>
execute_from_command_line(sys.argv)
文件/Library/Python/2.7/site-packages/django/core/management/__init__.py,第443行,在execute_from_command_line
utility.execute ()
文件/Library/Python/2.7/site-packages/django/core/management/__init__.py,第382行,执行
self.fetch_command(子命令).run_from_argv(self。 argv)
文件/Library/Python/2.7/site-packages/django/core/management/base.py,第196行,在run_from_argv
self.execute(* args,** options。 __dict__)
文件/Library/Python/2.7/site-packages/django/core/management/base.py,第232行,执行
output = self.handle(* args,**选项)
文件/Library/Python/2.7/site-packages/django/core/management/base.py,第371行,处理
return self.handle_noargs(** options)
文件/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py,第110行,handle_noargs
emit_post_sync_signal(created_models,verbosity,interaction ive,db)
文件/Library/Python/2.7/site-packages/django/core/management/sql.py,第189行,在emit_post_sync_signal
interactive = interactive,db = db)
文件/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py,第172行,发送
response = receiver(signal = self,sender = sender,** named)
文件/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py,第73行,在create_superuser
call_command(creationuperuser,interactive = True,数据库= db)
文件/Library/Python/2.7/site-packages/django/core/management/__init__.py,第150行,在call_command
中返回klass.execute(* args,**默认值)
文件/Library/Python/2.7/site-packages/django/core/management/base.py,第232行,执行
output = self.handle(* args,**选项)
文件/Library/Python/2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py,第70行,处理
default_username = get_default_usern ame()
文件/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py,第105行,get_default_username
default_username = get_system_username()
文件/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py,第85行,get_system_username
return getpass.getuser()。decode(locale.getdefaultlocale() [1])$ ​​b $ b文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py,第496行,getdefaultlocale
返回_parse_localename(本地名称)
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py,第428行,在_parse_localename
raise ValueError,'unknown locale:%s '%localename
ValueError:未知区域设置:UTF-8

从django的最终指南我正在显示其中一个模型。

  from django.db import models 
class Publisher(models.Model):
name = models.Cha rField(max_length = 30)
address = models.CharField(max_length = 50)
city = models.CharField(max_length = 60)
state_province = models.CharField(max_length = 30)
country = models.CharField(max_length = 50)
website = models.URLField()

def __str __(self):
return self.name

class Meta:
order = ['name']

setting.py数据库设置为: -

  DATABASES = {
'default':{
'ENGINE':'django .db.backends.postgresql_psycopg2',
'NAME':'books',
'USER':'postgres',
'PASSWORD':'******' b $ b'HOST':'localhost',
'PORT':'5432',
}
}

syncdb运行:

 创建表... 
创建表auth_permission
创建表auth_group_permissions
创建表auth_group
创建表auth_user_user_permissions
创建表auth_user_groups
创建表auth_user
创建表django_content_type
创建表django_session
创建表django_site
创建表books_publisher
创建表books_author
创建表books_book_authors
创建表books_book

是的,创建超级用户我得到错误。

解决方案

看起来你没有正确的本地人安装在您的系统上。



尝试在运行syncdb之前键入以下内容 -

  export LC_CTYPE = en_US.UTF-8 
export LC_ALL = en_US.UTF-8

(或者你当地应该是什么)。



或者将行添加到您的〜/ .bash_profile



看看这个问题


I am quite new to django and web development. Learning from the "Definitive guide to Django" when creating superuser I get the following error (OS mac10.8.2 & django1.4.3)

Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 73, in create_superuser
    call_command("createsuperuser", interactive=True, database=db)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
    return klass.execute(*args, **defaults)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 70, in handle
    default_username = get_default_username()
  File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username
    default_username = get_system_username()
  File "/Library/Python/2.7/site-packages/django/contrib/auth/management/__init__.py", line 85, in get_system_username
    return getpass.getuser().decode(locale.getdefaultlocale()[1])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

from the definitive guide to django i am showing one of the models.

from django.db import models
class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['name']

setting.py database settings are:-

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'books',
        'USER': 'postgres',
        'PASSWORD': '******',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

syncdb runs :

Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table books_publisher
Creating table books_author
Creating table books_book_authors
Creating table books_book

after yes to create superuser I get the error.

解决方案

It looks like you don't have the right locals installed on your system.

Trying typing the following before running syncdb -

export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

(or whatever your local should be).

Alternatively add the lines to your ~/.bash_profile

have a look at this question

这篇关于无法在syncdb之后创建超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆