お世話になっております。
Djangoを使用して、
python manage.py createsuperuser
コマンドを実行したところ、
django.db.utils.IntegrityError: duplicate key value violates unique constraint "authtoken_token_user_id_key"
DETAIL: Key (user_id)=(abcdef@gmail.com) already exists.
とエラーが返ってきてしまい、解決することができずにいます。
このコマンドを打つ前に、一度データベースをDROPして、migrationsディレクトリも
000* ファイルは全て消去した上で、migrateしていますので、該当すると思われる
authtoken_tokenテーブルも空の状態であり、何が悪くてこのエラーが発生しているのか
見当もつきません(Userテーブルも空です)。
どなたかご見識の方がいらっしゃいましたら、ぜひご教示いただけると幸いです。
よろしくお願いいたします。
追記(1)
dbshell実行時の出力は下記のようになります。
(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 (省略) 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.
追記2)
使用ソフトウェアのバージョン
python 3.5.2
OS Ubuntu 16.4 LTS (AWS)
Django-1.11.4
settings.py
import os from django.core.urlresolvers import reverse_lazy # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DJANGO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(DJANGO_ROOT) LOGIN_REDIRECT_URL = reverse_lazy('main') LOGIN_URL = reverse_lazy('login') LOGOUT_URL = reverse_lazy('logout') LOGIN_ERROR_URL = reverse_lazy('login') SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' DEBUG = True ALLOWED_HOSTS = ['app.myserver.com'] AUTH_USER_MODEL = 'user.RemoshinUser' AUTHENTICATION_BACKENDS = {'user.backends.RemoshinUserAuth',} # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken', 'corsheaders', 'remoshin', 'user', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'remoshin.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates/registration')] WSGI_APPLICATION = 'remoshin_user.wsgi.application' # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'db_name', 'USER': 'db_user', 'PASSWORD' : 'db_password', 'HOST' : '127.0.0.1', 'PORT' : 5432, } } # Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # REST API用の設定 JWT_AUTH = { 'JWT_VERIFY_EXPIRATION': False, 'JWT_AUTH_HEADER_PREFIX': 'JWT', } REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', ), 'NON_FIELD_ERRORS_KEY': 'detail', 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/'
あなたの回答
tips
プレビュー