解决Django创建admin用户时1406错误

[email protected] > createsuperuser
"D:\Program Files (x86)\JetBrains\PyCharm 5.0.3\bin\runnerw.exe" C:\Users\Administrator\Envs\mxonline\Scripts\python.exe "D:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py" createsuperuser "D:/Python27/Pycharm Project/MxOnline"
Username: kernel
Email address: [email protected]
Warning: Password input may be echoed.
Password: admin123456
Warning: Password input may be echoed.
Password (again): admin123456
Traceback (most recent call last):
File "D:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py", line 41, in <module>
run_module(manage_file, None, ‘__main__‘, True)
File "d:\python27\Lib\runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "d:\python27\Lib\runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "d:\python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "D:\Python27\Pycharm Project\MxOnline\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
utility.execute()
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\management\__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 52, in execute
return super(Command, self).execute(*args, **options)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\Administrator\Envs\mxonline\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 "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\contrib\auth\models.py", line 165, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\contrib\auth\models.py", line 148, in _create_user
user.save(using=self._db)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\contrib\auth\base_user.py", line 74, in save
super(AbstractBaseUser, self).save(*args, **kwargs)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\models\base.py", line 700, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Administrator\Envs\mxonline\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 "C:\Users\Administrator\Envs\mxonline\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 "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\models\base.py", line 851, in _do_insert
using=using, raw=raw)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\models\query.py", line 1039, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\models\sql\compiler.py", line 1064, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\django\db\backends\mysql\base.py", line 112, in execute
return self.cursor.execute(query, args)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\MySQLdb\cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Administrator\Envs\mxonline\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DataError: (1406, "Data too long for column ‘gender‘ at row 1")

这里提示gender长度太长
双击shift,输入错误中提示的那个字段

发现最大长度时5,但是默认值有6个字符,所以我们将其设为7个字符

然后重新makemigrations,migrate,createsuper,最后成功了

原文地址:http://blog.51cto.com/13559120/2286455

时间: 2024-10-30 17:16:24

解决Django创建admin用户时1406错误的相关文章

django 创建管理员用户

7.2 create 创建管理员用户: python manage.py run server python manage.py createsuperuser password :12345678912 7.3 admin.py 注册模型: from .models import Student,Grade class Register(admin.ModelAdmin): 7.3.1 #列表页属性 list_display 展示数据库字段名称包含字段列 list_filter过滤器过滤根据某

mysql 创建外键时发生错误的原因和解决方法

可以去网上查看错误号,就能知道到底哪里出错了 https://zhidao.baidu.com/question/359868536.html 这里1452对应的错误是因为建立外键的表中还有数据,所以外键建立失败,删除数据后再添加即可成功建立外键 原文地址:https://www.cnblogs.com/kinome/p/9051584.html

Mysql加入用户时的错误问题

比如:加入用户 insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); 报出:下面的错误 ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value错误 mysql5.1以上版本号,我是在5.6版本号上操作的. 正确的方法:能够用以下的命令: GRANT

解决Django站点admin管理页面样式表(CSS style)丢失

参照这篇教程激活完django自带服务器的admin管理页面后,照着教程所描述的那样,尝试打开http://127.0.0.1:8000/admin/,发现自己的浏览器显示如下 很明显可以看出,虽然业务逻辑正常表达,但这已经丢失了CSS,标准的白底黑字的交互环境,总让人感到不爽. 我查看命令行的报错信息,发现如下报错信息: 好了,看来我们已经找到问题所在,原来在Lib目录下mimetypes.py的文件编码问题,现在我们打开这个文件,在文件末尾添加: reload(sys) sys.setdef

Mysql添加用户时的错误问题

例如:添加用户 insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); 报出:以下的错误 ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value错误 mysql5.1以上版本,我是在5.6版本上操作的. 正确的方法:可以用下面的命令: GRANT U

解决在安装Python Scrapy时出现错误:Microsoft Visual C++ 14.0 is required...

在win7 64位系统,python版本3.6,安装Scrapy时出错报错,报错如下内容: 解决办法如下: 在https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted中下载文件Twisted-18.7.0-cp36-cp36m-win_amd64.whl,其中cp后面表示python版本,amd后面数字表示windows系统位数, 在CMD中执行如下命令: pip install C:\Users\CR\Downloads\Twisted-18.7.

教你一招:解决安装或卸载office时 提示错误2503 2502 发生了内部错误

问题重现: 解决办法:使用软件卸载工具 Uninstall Tool 3.5.1 中文破解版强制删除文件,非常暴力,完美解决. 解决过程一览: 工具下载地址: 软件卸载工具 Uninstall Tool 3.5.1 中文破解版

yarn 创建react项目时出现错误

出现一下错误 error Incorrect integrity when fetching from the cache info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. 或者 error Incorrect integrity when fetching from the cache info Visit https://yarnpkg.com/en/docs/cli/ad

解决Django发送中文邮件时的编码及乱码问题

参考自---http://blog.csdn.net/clh604/article/details/9274793 #-*- coding=utf8 -*- from email.message import Message from email.header import Header import smtplib msg=Message() msg['Mime-Version']='1.0' msg['Content-type']='text/html' msg['From']="flow*