Answer the question
In order to leave comments, you need to log in
Django and PostgreSQL: What to do with django.db.utils.ProgrammingError?
I wrote a project in SQLite3 and decided to set it up for PostgreSQL by setting the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3 'or 'oracle'.
'NAME': 'company_base', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'postgres', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
}
}
Installed psycopg:
pip install psycopg2
After I enter python3 manage.py migrate, it gives the traceback shown below. Weird fact: if you commit the application to Installed_apps, the migration will work fine, but the error returns, you should include the application back. There are no problems with SQLite3.
traceback:
Traceback (most recent call last):
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "main_app_sector" does not exist
LINE 1: ...n_app_sector"."id", "main_app_sector"."name" FROM "main_app_...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/apps/registry.py", line 116, in populate
app_config.ready()
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/home/anton/virtenvs/com_env/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/anton/Django-u/company_base/main_app/admin.py", line 3, in <module>
from .forms import *
File "/home/anton/Django-u/company_base/main_app/forms.py", line 28, in <module>
class ProfileFilterForm(forms.Form):
File "/home/anton/Django-u/company_base/main_app/forms.py", line 30, in ProfileFilterForm
sector = forms.ChoiceField(label='Отдел', required=False, choices=build_sectors_list(), widget=forms.Select(attrs={'name':'sector', 'style':'selector_element',}))
File "/home/anton/Django-u/company_base/main_app/forms.py", line 18, in build_sectors_list
for i in sectors:
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/models/query.py", line 250, in __iter__
self._fetch_all()
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 894, in execute_sql
raise original_exception
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 884, in execute_sql
cursor.execute(sql, params)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/backends/utils.py", line 80, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/anton/virtenvs/com_env/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "main_app_sector" does not exist
LINE 1: ...n_app_sector"."id", "main_app_sector"."name" FROM "main_app_...
Answer the question
In order to leave comments, you need to log in
A number of errors:
1. If you created a virtual environment, then why enter python3 manage.py migrate, you can just python manage.py migrate
2. Look what you wrote in the models, the problem is in the connections.
3. makemigrations I hope completed?
>> "main_app_sector" - see this entry
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question