我很困惑如何从终端使用'python manage.py createsuperuser'命令。
当我运行此命令时,它会说
django.db.utils.IntegrityError:重复键值违反唯一约束“authtoken_token_user_id_key” 详细信息:Key(user_id)=(abcdef@gmail.com)已存在。
但是,在使用此命令之前,我删除了数据库并在删除迁移目录中的000 *文件后重新创建。
我检查过authtoken_token和user表中没有行。 我不知道出了什么问题。
请给我一些建议。
(remoshin) ubuntu@ip-172-31-33-33:~/remoshin/remoshin$ python3 manage.py makemigrations
(remoshin) ubuntu@ip-172-31-33-33:~/remoshin/remoshin$ python3 manage.py migrate
(remoshin) ubuntu@ip-172-31-33-33:~/remoshin/remoshin$ python3 manage.py dbshell
psql (9.5.8)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
remoshin_maindb=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------------------------------------+-------+---------
public | auth_group | table | remosys
public | auth_group_permissions | table | remosys
public | auth_permission | table | remosys
public | authtoken_token | table | remosys
public | django_admin_log | table | remosys
public | django_content_type | table | remosys
public | django_migrations | table | remosys
public | django_session | table | remosys
public | remosys_chat_detail_tbl | table | remosys
public | remosys_chat_tbl | table | remosys
public | remosys_clinic_ipaddress_tbl | table | remosys
public | remosys_clinic_open_tbl | table | remosys
public | remosys_clinic_tbl | table | remosys
public | remosys_consultation_menu_tbl | table | remosys
public | remosys_consultation_tbl | table | remosys
public | remosys_department_tbl | table | remosys
public | remosys_error_tbl | table | remosys
public | remosys_menu_tbl | table | remosys
public | remosys_refund_request_tbl | table | remosys
public | remosys_remoshin_doctor_tbl | table | remosys
public | remosys_remoshin_manager_tbl | table | remosys
public | remosys_remoshin_manager_tbl_groups | table | remosys
public | remosys_remoshin_manager_tbl_user_permissions | table | remosys
public | remosys_remoshin_user_tbl | table | remosys
public | remosys_statement_tbl | table | remosys
(25 rows)
remoshin_maindb=# select * from authtoken_token;
key | created | user_id
-----+---------+---------
(0 rows)
remoshin_maindb=# select * from remosys_remoshin_user_tbl;
remoshin_maindb=# select * from authtoken_token_user_id_key";
remoshin_maindb"# select max(id) from authtoken_token_user_id_key;
remoshin_maindb"#
remoshin_maindb=# \q
(remoshin) ubuntu@ip-172-31-33-33:~/remoshin/remoshin$ python3 manage.py createsuperuser
(omit)
File "/home/ubuntu/remoshin/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.IntegrityError: duplicate key value violates unique constraint "authtoken_token_user_id_key"
DETAIL: Key (user_id)=(abcdef@gmail.com) already exists.