python创建django后台管理员出现以下错误:
Traceback (most recent call last):
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 101, in execute
return self.cursor.execute(query, args)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 893, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1103, in _read_query_result
result.read()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1396, in read
first_packet = self.connection._read_packet()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1059, in _read_packet
packet.check_error()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, "Duplicate entry '' for key 'mobile'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
return super(Command, self).execute(*args, **options)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 183, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/contrib/auth/models.py", line 170, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/contrib/auth/models.py", line 153, in _create_user
user.save(using=self._db)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 80, in save
super(AbstractBaseUser, self).save(*args, **kwargs)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/base.py", line 808, in save
force_update=force_update, update_fields=update_fields)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/base.py", line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/base.py", line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/base.py", line 963, in _do_insert
using=using, raw=raw)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
cursor.execute(sql, params)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 101, in execute
return self.cursor.execute(query, args)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/cursors.py", line 170, in execute
result = self._query(query)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/cursors.py", line 328, in _query
conn.query(q)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 893, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1103, in _read_query_result
result.read()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1396, in read
first_packet = self.connection._read_packet()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 1059, in _read_packet
packet.check_error()
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/home/python/.virtualenvs/meiduo1/lib/python3.5/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.IntegrityError: (1062, "Duplicate entry '' for key 'mobile'")
错误分析:数据库中的手机号不能重复
众所周知我们创建后台管理原时候是没有设置手机号的(如下所示):
所以在收据库中已有管理员的话,已经有一个手机号为空,我们再次创建管理员就会有手机号重复的现象存在
解决方案:
把数据库中的管理员设置一个手机号