在tool-run manage.py task 运行createsuperuser,提示输入用户名,邮件,密码
manage.py@mxproject > createsuperuser
"F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\bin\runnerw.exe" "F:\Program Files (x86)\Python3\Scripts\mxenv\Scripts\python.exe" "F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py" createsuperuser D:/python/mxproject
Username: admin
Email address: [email protected]
Warning: Password input may be echoed.
Password: 123asdfgH
Warning: Password input may be echoed.
Password (again): 123asdfgH
结果出现:
Traceback (most recent call last):
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\mysql\base.py", line 112, in execute
return self.cursor.execute(query, args)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\cursors.py", line 166, in execute
result = self._query(query)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\cursors.py", line 322, in _query
conn.query(q)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 1019, in _read_query_result
result.read()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 981, in _read_packet
packet.check_error()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.DataError: (1406, "Data too long for column 'gender' at row 1")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py", line 41, in
run_module(manage_file, None, '__main__', True)
File "f:\program files (x86)\python3\Lib\runpy.py", line 196, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "f:\program files (x86)\python3\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "f:\program files (x86)\python3\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:/python/mxproject\manage.py", line 10, in
execute_from_command_line(sys.argv)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
utility.execute()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\core\management\__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 52, in execute
return super(Command, self).execute(*args, **options)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 173, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\contrib\auth\models.py", line 165, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\contrib\auth\models.py", line 148, in _create_user
user.save(using=self._db)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\contrib\auth\base_user.py", line 74, in save
super(AbstractBaseUser, self).save(*args, **kwargs)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\base.py", line 700, in save
force_update=force_update, update_fields=update_fields)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\base.py", line 728, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\base.py", line 812, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\base.py", line 851, in _do_insert
using=using, raw=raw)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\models\sql\compiler.py", line 1064, in execute_sql
cursor.execute(sql, params)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\django\db\backends\mysql\base.py", line 112, in execute
return self.cursor.execute(query, args)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\cursors.py", line 166, in execute
result = self._query(query)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\cursors.py", line 322, in _query
conn.query(q)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 1019, in _read_query_result
result.read()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 981, in _read_packet
packet.check_error()
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "F:\Program Files (x86)\Python3\Scripts\mxenv\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.DataError: (1406, "Data too long for column 'gender' at row 1")
在pycharm中按快捷键ctr+h,快速查找gender,找到对应的字段
可以看到设置的字符长度是5,可是female有6个字节,所以修改max_length=7
然后执行
makemigrations users
再执行
migrate users
然后重新执行创建admin后台的超级账户就可以了