2

スーパーユーザーの作成時にsyncdbが失敗する

Django: v 1.2.4 Python: 2.6 MySQL サーバー: 5.5 Windows 7 Extra: MySQL-Python v1.2.3

問題を再現する手順は何ですか? 1. 上記のプログラムをインストールします 2. プロジェクトを作成します 3. syncdb を実行します

注: UTF 8 をサポートするために mySQL をインストールしました。また、CREATE DTABASE mysite_db CHARACTER SET = UTF8; を使用して mysite_db データベースを作成します。

期待される出力は何ですか?代わりに何が見えますか?

syncdb は、次のように必要なテーブルを作成します。


C:\DjangoProjects\mysite>python manage.py syncdb
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 auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superuse
rs defined.
Would you like to create one now? (yes/no):

「はい」を選択すると、次のエラーが表示されます。


Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
    utility.execute()
  File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 351,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python26\lib\site-packages\django\core\management\commands\syncdb.py"
, line 103, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "C:\Python26\lib\site-packages\django\core\management\sql.py", line 182,
in emit_post_sync_signal
    interactive=interactive, db=db)
  File "C:\Python26\lib\site-packages\django\dispatch\dispatcher.py", line 172,
in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Python26\lib\site-packages\django\contrib\auth\management\__init__.py
", line 44, in create_superuser
    call_command("createsuperuser", interactive=True)
  File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line
166, in call_command
    return klass.execute(*args, **defaults)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python26\lib\site-packages\django\contrib\auth\management\commands\cr
eatesuperuser.py", line 71, in handle
    User.objects.get(username=default_username)
  File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 132, in
 get
    return self.get_query_set().get(*args, **kwargs)
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 342, in g
et
    num = len(clone)
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 80, in __
len__
    self._result_cache = list(self.iterator())
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line 271, in i
terator
    for row in compiler.results_iter():
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 67
7, in results_iter
    for rows in self.execute_sql(MULTI):
  File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 73
2, in execute_sql
    cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 15, in e
xecute
    return self.cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 86
, in execute
    return self.cursor.execute(query, args)
  File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 175, in execute
    if not self._defer_warnings: self._warning_check()
  File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 89, in _warning_
check
    warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Incorrect string value: '\xED' for column 'username'
at row 1

使用している製品のバージョンは何ですか? どのオペレーティングシステムで?

Django: v 1.2.4 Python: 2.6 MySQL サーバー: 5.5 Windows 7 Extra: MySQL-Python v1.2.3

以下の追加情報を提供してください。

また、mySQL C++ および ODBC データベース コネクタもインストールされています。どんな助けでも大歓迎です。

4

2 に答える 2

0

models.py またはフィクスチャのどこかに Unicode 文字があるようです。ファイルを UTF-8 に変換し、最初の行にコメントを追加します。

#coding-utf-8

また、次のように、Unicode 文字列を追加する前にu、次のようにします。

name = CharField(maxlength=255, default=u"утф-8 строка");
于 2011-01-25T15:11:26.780 に答える
0

開発用マシンへのログインに Unicode 文字が含まれているようです。createsuperuser.pyモジュールがUserそのユーザー名のオブジェクトを検索すると、MySQL がそれらの文字を想定していないため、barfing が発生します。MySQL テーブルの照合設定を変更してUTF-8 を受け入れるか、Unicode 文字を含まないユーザー名を使用することができます (これはあまり良いオプションではありません)。

トレースバックの実際の失敗はcreatesuperuser.py71 行目から始まり、59 行目から発生します

        try:
         default_username = getpass.getuser().replace(' ', '').lower()
     except (ImportError, KeyError):
         # KeyError will be raised by os.getpwuid() (called by getuser())
         # if there is no corresponding entry in the /etc/passwd file
         # (a very restricted chroot environment, for example).
         default_username = ''

     # Determine whether the default username is taken, so we don't display
     # it as an option.
     if default_username:
         try:
             User.objects.get(username=default_username)
         except User.DoesNotExist:
             pass
         else:
             default_username = ''

経由でユーザー名を取得しgetpass、それをテーブルで検索しようとしていUserます。

于 2011-01-25T15:16:26.240 に答える