1. 程式人生 > >解決Django創建admin用戶時1406錯誤

解決Django創建admin用戶時1406錯誤

.com err 分享 TBase ogr ddr output nec none

manage.py@MxOnline > 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,最後成功了

解決Django創建admin用戶時1406錯誤