Thomas Duval
Thomas Duval

Reputation: 51

django.db.utils.ProgrammingError: relation "administration_parks" does not exist

I had a problem, and I really struggled to figure out what was wrong. I made an application with the Django framework. Everything worked fine on my local machine, including the DB. Only, when I put my application on the server, I wanted to migrate the database, but I had this error :

Traceback (most recent call last):
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "administration_parks" does not exist
LINE 1: ...name", "administration_parks"."availability" FROM "administr...
                                                             ^


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

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 75, in handle
    self.check(databases=[database])
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
    all_issues = checks.run_checks(
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/thomas/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/thomas/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check
    for pattern in self.url_patterns:
  File "/home/thomas/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/thomas/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 598, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/thomas/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/thomas/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/thomas/AnimauBoue/AnimauBoue/urls.py", line 21, in <module>
    url(r'^', include('administration.urls')),
  File "/home/thomas/env/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/thomas/AnimauBoue/administration/urls.py", line 4, in <module>
    from .views import index
  File "/home/thomas/AnimauBoue/administration/views.py", line 12, in <module>
    from .forms import ConnectionForm, UpdateDataForm, AddClientForm, SelectParkAndClientForm, DogForm, AddDog
  File "/home/thomas/AnimauBoue/administration/forms.py", line 26, in <module>
    class SelectParkAndClientForm(forms.Form):
  File "/home/thomas/AnimauBoue/administration/forms.py", line 31, in SelectParkAndClientForm
    for park in parks:
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
    self._fetch_all()
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/models/query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/thomas/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "administration_parks" does not exist
LINE 1: ...name", "administration_parks"."availability" FROM "administr...

As this problem resist for two days now, I create this post in the case where some of you have an idea of what could be the issue in my code. Thanx by advance for your help.

Upvotes: 0

Views: 375

Answers (2)

user20538846
user20538846

Reputation: 1

You can fin the answer of your question here django.db.utils.ProgrammingError: relation "auth_permission" does not exist

In this comment django.db.utils.ProgrammingError: relation "auth_permission" does not exist

I think you are trying to make a query in your SelectParkAndClientForm, you can do it in the __init__ to solve the problem.

Upvotes: 0

Thomas Duval
Thomas Duval

Reputation: 51

In fact, I came to understand that Django, when it migrates a DB, seems to perform some manipulation on views from urls.py of applications. And in my case, this was the problem. So the solution was:

  1. Comment all my url patterns, and then do the migrations, and there it worked !

  2. At this stage, it allowed me to create the tables present in my models. But Django's default tables weren't created since I no longer had any url schema. So I uncommented all the urls in urls.py, do a new pull on my server, and redo the migrations. And there, all the tables created by default by django have been created.

Since I struggled 2 days on this problem, I post here my experience hoping that it can help some of you!

Upvotes: 0

Related Questions