Django python manage.py createsuperuser実行時にエラー「django.db.utils.OperationalError: no such table: auth_user」が発生した場合の対処法
python manage.py createsuperuserでスーパーユーザー作成時にエラーが発生したので、対応方法を記載
環境
- OS CentOS Linux release 8.0.1905 (Core)
- Python 3.6.8
- pip 9.0.3
- django 3.0
エラー内容
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/testuser/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/testuser/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/.local/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/testuser/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/home/testuser/.local/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/testuser/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 100, in handle
default_username = get_default_username()
File "/home/testuser/.local/lib/python3.6/site-packages/django/contrib/auth/management/__init__.py", line 140, in get_default_username
auth_app.User._default_manager.get(username=default_username)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/query.py", line 411, in get
num = len(clone)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/query.py", line 258, in __len__
self._fetch_all()
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/query.py", line 57, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1137, in execute_sql
cursor.execute(sql, params)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/testuser/.local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auth_user
no such table: auth_userとなっているので、先にmigrateしてあげる
python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying sessions.0001_initial... OK
-
前の記事
Nuxt.js vue-highlight-wordsを使用して指定した文字列をハイライト表示する 2020.02.14
-
次の記事
Nuxt.js vue-simple-context-menuを使用して左クリックや右クリックでコンテキストメニューを表示する 2020.02.16
コメントを書く