Python Forum
[Django] Getting exception: "no such table: auth_user"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Django] Getting exception: "no such table: auth_user"
#1
I get this exception when I try to login to the admin site. I've been trying to figure out why this exception was occurring and I can't seem to fix it. The first thing I tried was deleting the database and migrations and then re-migrating. However I noticed a problem with the migration, so I made a new project, remade the one app I had, then copied and pasted all the files I had edited/made such as templates, static, settings, views, urls, models, etc. Then I migrated before re-uploading it back to where it could be run by webfaction and displayed onto the domain. Even after resetting all that I'm still getting the same exception, and I don't know what to do about it. The traceback is below:
Error:
Traceback (most recent call last): File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/sqlite3/base.py", line 396, in execute return Database.Cursor.execute(self, query, params) The above exception (no such table: auth_user) was the direct cause of the following exception: File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/admin/sites.py", line 407, in login return LoginView.as_view(**defaults)(request) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper return view(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/auth/views.py", line 63, in dispatch return super().dispatch(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/views/generic/edit.py", line 141, in post if form.is_valid(): File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/forms/forms.py", line 180, in is_valid return self.is_bound and not self.errors File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/forms/forms.py", line 175, in errors self.full_clean() File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/forms/forms.py", line 377, in full_clean self._clean_form() File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/forms/forms.py", line 404, in _clean_form cleaned_data = self.clean() File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/auth/forms.py", line 214, in clean self.user_cache = authenticate(self.request, username=username, password=password) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/auth/__init__.py", line 72, in authenticate user = backend.authenticate(request, **credentials) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/auth/backends.py", line 46, in authenticate user = UserModel._default_manager.get_by_natural_key(username) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/contrib/auth/base_user.py", line 44, in get_by_natural_key return self.get(**{self.model.USERNAME_FIELD: username}) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/models/query.py", line 411, in get num = len(clone) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/models/query.py", line 258, in __len__ self._fetch_all() File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/models/query.py", line 1261, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/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/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/models/sql/compiler.py", line 1152, in execute_sql cursor.execute(sql, params) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 100, in execute return super().execute(sql, params) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/sheepposu78/webapps/gamebg_django_application/lib/python3.8/Django-3.0.8-py3.8.egg/django/db/backends/sqlite3/base.py", line 396, in execute return Database.Cursor.execute(self, query, params) Exception Type: OperationalError at /admin/login/ Exception Value: no such table: auth_user
EDIT: I also noticed another thing involving the database. Usually it would be called db.sqlite3 but instead it is named after the database that I made with webfaction. Which I assume is because of what I put in the settings file. If it helps the code for the database in settings.py is below:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'gamebg_database',
        'USER': '****',
        'PASSWORD': '****',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}
Reply
#2
what does AUTH_USER_MODEL in settings contain?
Reply
#3
I was planning to make a Custom user model, so I made it after posting this thread. AUTH_USER_MODEL points to that user model. So now I have the same error but different, though I assume it involves the same problem but with a different table name. "No such table main_user", and I assume that the main in main_user refers to the name of the app, which is "main". I was thinking it might be a problem with one of the files I'm copying over, so I'm going to create a whole new project and build it little by little to find the source of the error.
Reply
#4
I started a whole new project. From there I copied over the templates and static as I was certain that has nothing to do with the problem. I then made the home_page in views, tested, worked fine, and from there started to build a few more things. I then moved the custom user model, forms, and such into there places, looked over them, made a couple changes, and from there just built everything back to the way it was. It's now working fine.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Upgraded Django, `AdminSplitDateTime` causes exception on `list` object 1780yz 2 2,950 Feb-24-2021, 04:47 PM
Last Post: 1780yz
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,247 Jun-30-2019, 12:21 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020