#15162 closed Bug (duplicate)
syncdb fails when creating super user - Django: v 1.2.4 Python: 2.6 MySQL Server: 5.5 Windows 7 Extra: MySQL-Python v1.2.3
| Reported by: | david_heagney | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.3 |
| Severity: | Normal | Keywords: | syncdb mysql |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | UI/UX: |
Description (last modified by )
syncdb fails when creating super user - Django: v 1.2.4 Python: 2.6 MySQL Server: 5.5 Windows 7 Extra: MySQL-Python v1.2.3
What steps will reproduce the problem?
- install the above programs
- create a project
- run syncdb
Note: I have installed mySQL to support UTF 8. I also create the
mysite_db database using CREATE DTABASE mysite_db CHARACTER SET =
UTF8;
What is the expected output? What do you see instead?
syncdb create the required tables as follows:
--------------------------------------------------------------------------------------------------------------------- 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): ---------------------------------------------------------------------------------------------------------------------
I select 'YES' and get the following error:
---------------------------------------------------------------------------------------------------------------------
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
---------------------------------------------------------------------------------------------------------------------
What version of the product are you using? On what operating system?
Django: v 1.2.4 Python: 2.6 MySQL Server: 5.5 Windows 7 Extra: MySQL-Python v1.2.3
Please provide any additional information below.
I also have mySQL C++ and ODBC database connectors installed. Any help is greatly appreciated.
Change History (7)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
| Description: | modified (diff) |
|---|
[Re-formatted output, please use the ' Preview' button at least once before submitting the ticket, use WikiFormatting when creating the description and try to paste a well formatted Python traceback from your OS console screen (in the one you pasted each line is broken in three lines and it dificutls its reading)]
comment:3 by , 15 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
I couldn't reproduce this on Windows, http://d.pr/pO9N
comment:4 by , 15 years ago
| Has patch: | set |
|---|---|
| Resolution: | worksforme |
| Severity: | → Normal |
| Status: | closed → reopened |
| Type: | → Uncategorized |
| Version: | 1.2 → 1.3 |
I had the same problem - it is caused by non-ascii characters in the Windows username (in my case the username is Paweł).
quick fix (just ignoring the non-ascii character):
contrib\auth\management\commands\createsuperuser.py, line 61:
++default_username = getpass.getuser().replace(' ', ).decode('ascii','ignore').lower()
--default_username = getpass.getuser().replace(' ', ).lower()
comment:5 by , 15 years ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
Patch needs improvement - there is no reason we can't use non ASCII in usernames. The problem is probably that the getpass.getuser() is returning a byte string, rather than a unicode object. This presumably needs to take the locale into account, probably using locale.getdefaultlocale(). That should work on Linux, I don't know about Windows.
comment:6 by , 15 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | reopened → closed |
This is the same as #15778 which is newer but has discussion of a proper fix, so I'm closing this a dupe of that.
Note: I have confirmed the mySQL DB is UTF-8. I deleted and recreated using < CREATE DATABASE mysite_db DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;> and got the same error. Thanks.