Django Setup: No Such Table auth_user

creyD

Every time we set up our Django project in a new environment and try to initiate the server (migrate or runserver) the error message django.db.utils.OperationalError: no such table: auth_user shows (full error message below).

I am assuming this comes from using the user model as a foreign key in some of our models (example seen below) and as a new system is set up (no database created yet) Django tries to create the table for our custom model and fails because of the foreign key -the user table- as it wasn't created yet.

# Model for projects (example)
class Projekt(models.Model):
    project_name = models.CharField(max_length=100, unique=True)
    project_manager = models.ForeignKey(User, related_name="Manager", on_delete=models.DO_NOTHING)

My question is: is there any best practice on what to do to prevent this? For now, we are just copying the database from our running systems for every new developer we are getting, which works for now, but is not valid for open source distribution of the software.

I tried different stuff like this and this) already, but this didn't work out. I encountered this problem in each and every of my Django projects.


USERNAME$ python3 manage.py migrate
  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
      return Database.Cursor.execute(self, query, params)
  sqlite3.OperationalError: no such table: auth_user

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
    File "manage.py", line 15, in <module>
      execute_from_command_line(sys.argv)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
      utility.execute()
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 350, in execute
      self.check()
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check
      include_deployment_checks=include_deployment_checks,
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 60, in _run_checks
      issues.extend(super()._run_checks(**kwargs))
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 366, in _run_checks
      return checks.run_checks(**kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks
      new_errors = check(app_configs=app_configs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
      all_namespaces = _load_all_namespaces(resolver)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
      url_patterns = getattr(resolver, 'url_patterns', [])
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/urls/resolvers.py", line 533, in url_patterns
      patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
      res = instance.__dict__[self.name] = self.func(instance)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
      return import_module(self.urlconf_name)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/USERNAME/Documents/PROJECTS/PROJECTFOLDER/PROJECT_NAME/urls.py", line 8, in <module>
      path('i/', include('APP1.urls')), # Private space/ Development space
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
      urlconf_module = import_module(urlconf_module)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/USERNAME/Documents/PROJECTS/PROJECTFOLDER/APP1/urls.py", line 4, in <module>
      from . import views
    File "/USERNAME/Documents/PROJECTS/PROJECTFOLDER/APP1/views.py", line 11, in <module>
      from .forms import AddProject, AddTicket
    File "/USERNAME/Documents/PROJECTS/PROJECTFOLDER/APP1/forms.py", line 5, in <module>
      class AddProject(forms.Form):
    File "/USERNAME/Documents/PROJECTS/PROJECTFOLDER/APP1/forms.py", line 7, in AddProject
      project_manager = forms.ChoiceField(choices=[(user.id, user) for user in User.objects.all()])
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/query.py", line 268, in __iter__
      self._fetch_all()
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _fetch_all
      self._result_cache = list(self._iterable_class(self))
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/query.py", line 54, in __iter__
      results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
      cursor.execute(sql, params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
      return super().execute(sql, params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
      return executor(sql, params, many, context)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
      return self.cursor.execute(sql, params)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
      return Database.Cursor.execute(self, query, params)
  django.db.utils.OperationalError: no such table: auth_user
skalet

Add migrations folder to git. This contains the information needed to create a new database correctly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Password not saving to auth_user table in Django

django: User Registration with error: no such table: auth_user

merge django's auth_user with existing user table

Django superuser fixture error - no such table: auth_user

Creating a New Table (Model) and Relating it to auth_user in Django

Django testing on separate database giving "OperationalError: no such table: auth_user"

How to add 'mobile' field to default auth_user table in User model in django?

Is it safe to share `auth_user` and `django_session` table for intranet Django projects?

unable to create superuser in django getting error "django.db.utils.OperationalError: no such table: auth_user"

Django deployment on heroku throws django.db.utils.OperationalError: no such table: auth_user

Django.. I need to have a DateField which should be updated when auth_user table gets updated

I'd like to get some data from auth_user table on Django

Django: How do I use is_active of auth_user table?

how to update django auth_user with queryset?

Django add field to auth_user

Renaming auth_user breaks migrations on fresh setup

Graphite Web Error Log, OperationalError: no such table: auth_user

How to add columns to auth_user in django postgresql?

Error Key (user_id)=(1) is not present in table "auth_user" when migrating

Create Django app with no User model - 3.1.3 wants to migrate auth_user?

Failed to setup settings.AUTH_USER_MODEL in Django

"django.db.utils.ProgrammingError: relation "auth_user" does not exist" Django V2.0

Django - No such table: main.auth_user__old

Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist

django 1.7 relation "auth_user" does not exist in migrate but fine in tests

django.db.utils.OperationalError: foreign key mismatch - "project_projectpage" referencing "auth_user"

How can i add extra model fields to default auth_user model using django

Django: relation "auth_user" already exists when executing manage.py test myApp

django application on heroku gives 'Programming error at /admin/login "auth_user" does not exist.' on login

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive