Forums

Problems with migrate

Hello! I tried deploy existing web-app and followed instructions, but when I typed:

python manage.py migrate

I got this error:

Traceback (most recent call last):
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "core_tires" does not exist
LINE 1: SELECT DISTINCT "core_tires"."producer" FROM "core_tires"

And very long TRACEBACK.

How I can import scheme of my localy db postgres? Where should to do pg_dump?

seems like perhaps the core_tires table is not created in migrations? do a makemigrations for it first before you migrate?

I tried makemigrations and get the same error. Also I tried

python manage.py migrate admin zero --fake

python manage.py migrate admin zero

and evey time get this error.

This is the traceback of "python manage.py makemigrations":

Traceback (most recent call last):
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "core_tires" does not exist
LINE 1: SELECT DISTINCT "core_tires"."producer" FROM "core_tires"
                                                 ^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 366, in execute
self.check()
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = self._run_checks(
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/management/base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/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 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/dzhem911/deploy_tkontakta/t_kontakta/urls.py", line 11, in <module>
path('', include('core.urls')),
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/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 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/dzhem911/deploy_tkontakta/core/urls.py", line 2, in <module>
from . import views
File "/home/dzhem911/deploy_tkontakta/core/views.py", line 5, in <module>
from .filters import TireFilter
File "/home/dzhem911/deploy_tkontakta/core/filters.py", line 8, in <module>
class TireFilter(django_filters.FilterSet):
File "/home/dzhem911/deploy_tkontakta/core/filters.py", line 22, in TireFilter
producer_query_choices = [(id, id) for id in producer_query]
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/models/query.py", line 276, in __iter__
self._fetch_all()
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/models/query.py", line 1261, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/models/query.py", line 184, in __iter__
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1096, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1144, in execute_sql
cursor.execute(sql, params)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/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/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "core_tires" does not exist
LINE 1: SELECT DISTINCT "core_tires"."producer" FROM "core_tires"

hmm. it definitely feels like there is something out of sync between your migration files and your database state. if you are still developing and don't have any data, perhaps try deleting all the databases and starting over again?

I tried that you said, but it's not changed. I write code in containers, so my db postgres inside cont. I made pg_dump, and after that load '.sql'-file in postgres pythonanywhere. When I load it, console write some errors, but so-so datas loaded and render on the web-site pages. But when I try add any data via django-admin, I get page with server error-500. In error-logs:

File "/home/dzhem911/.virtualenvs/tkontakta_virtualenv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.SyntaxError: syntax error at or near "ON"
LINE 1: ...ory" ("tires_id", "category_id") VALUES ('12', 2) ON CONFLIC...

I think that I didn’t upload the data correctly, but I don’t know how to upload it from the container to the site in any other way.

given that everything is so messed up, could you perhaps try not to restore your database and instead create a new one and try putting in new data to make it work?

So I get the first error with trackeback that I pointed above.