Question

[Solved] django.db.utils.OperationalError: no such table: auth_user

After I install Django-userena,there is an error
my django version :1.9.5
I just install django-userena step by step ,but when i migrate it ,an error happend and I don’t how to solve it.

    Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "C:Python27libsite-packagesdjangocoremanagement__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "C:Python27libsite-packagesdjangocoremanagement__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:Python27libsite-packagesdjangocoremanagementbase.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:Python27libsite-packagesdjangocoremanagementbase.py", line 399, in execute
    output = self.handle(*args, **options)
  File "C:Python27libsite-packagesdjangocoremanagementcommandsmigrate.py", line 204, in handle
    emit_post_migrate_signal(self.verbosity, self.interactive, connection.alias)
  File "C:Python27libsite-packagesdjangocoremanagementsql.py", line 50, in emit_post_migrate_signal
    using=db)
  File "C:Python27libsite-packagesdjangodispatchdispatcher.py", line 192, in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:Python27libsite-packagesguardianmanagement__init__.py", line 33, in create_anonymous_user
    User.objects.get(**lookup)
  File "C:Python27libsite-packagesdjangodbmodelsmanager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:Python27libsite-packagesdjangodbmodelsquery.py", line 381, in get
    num = len(clone)
  File "C:Python27libsite-packagesdjangodbmodelsquery.py", line 240, in __len__
    self._fetch_all()
  File "C:Python27libsite-packagesdjangodbmodelsquery.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "C:Python27libsite-packagesdjangodbmodelsquery.py", line 52, in __iter__
    results = compiler.execute_sql()
  File "C:Python27libsite-packagesdjangodbmodelssqlcompiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "C:Python27libsite-packagesdjangodbbackendsutils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:Python27libsite-packagesdjangodbbackendsutils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:Python27libsite-packagesdjangodbutils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:Python27libsite-packagesdjangodbbackendsutils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:Python27libsite-packagesdjangodbbackendssqlite3base.py", line 323, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auth_user

apps:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    'userena',
    'guardian',
    'easy_thumbnails',
    'accounts',    
]
Enquirer: ???

||

Solution #1:

./manage.py migrate

if your Django version is 1.9 or lower, use

./manage.py syncdb

then

python manage.py createsuperuser

more details on https://github.com/django/django/blob/master/django/contrib/auth/forms.py

May it help

Respondent: Cirno Maple

Solution #2:

The problem is this line:

File "C:Python27libsite-packagesguardianmanagement__init__.py", line 33, in create_anonymous_user
User.objects.get(**lookup)

guardianmanagement__init__.py is calling User before it is defined.

Why is it called before it is defined?
…well, it is called by makemigrations to find out if there are changes in the db to define them (the changes that are found)

…so this is a “chicken and egg” problem.

I have the same error with a similar problem but the offending code was my own code (not a library like guardian)

My code was like this:

CHAT_BOT_USER, created = User.objects.get_or_create(username="rosty", email=settings.EMAIL_HOST_USER)

The offending part is the User being used before the auth_user table is created

I solved by only executing the code when the table is present. This happens when there is no OperationError. And you can know it with a try/except like this:

from django.db import OperationalError

try:
    CHAT_BOT_USER, created = User.objects.get_or_create(username='rosty', email=settings.EMAIL_HOST_USER)

except OperationalError:
    CHAT_BOT_USER = None

if created:
    CHAT_BOT_USER.set_password(settings.EMAIL_HOST_PASSWORD)
    CHAT_BOT_USER.save()

This way makemigrations runs the except code and runserver runs the try code.

Note the created boolean, you may use any other way to avoid makemigration run code that depends on the User.objects.... results

Respondent: elingerojo

Solution #3:

I was get same error and to fix the same, I checked if the mentioned table in error is present in connected DB or not. It was not. Applied migration again and it worked.

python manage.py migrate

python manage.py makemigrations
Respondent: Bhupinder Yadav

Solution #4:

  python manage.py migrate --run-syncdb  

This command will look into which tables were not created and will create all the needed tables.

Respondent: Aram Simonyan

Solution #5:

RUN: python3 manage.py migrate

Respondent: Shah Vipul

Solution #6:

I have came across same error while working with chatrooms.
I resolved using deleting the db.sqlite3 file and deleting the 0001_initial.py file in the migrations folder of the app and then i executed the following statements:-

python manage.py makemigrations
python manage.py migrate

then i was able to create a superuser using

python manage.py createsuperuser

Thats it error resolved!

Respondent: Ragav Subramanian

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy