ОШИБКА: отношение “results_results” не существует
LINE 1: UPDATE “results_results” SET “pvalues” =
Стек такой: Django 3.0 + psycopg2 2.8.6 + postgres 12 + windows 10
settings.py:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }, 'results': { 'ENGINE':'django.db.backends.postgresql_psycopg2', 'OPTIONS': {'options': '-c search_path=results,public'}, 'NAME': 'results', 'USER': 'user', 'PASSWORD': 'password', 'HOST': '127.0.0.1', 'PORT': '5432' } }
views.py
def result(req, res_id): inp = Input.objects.get(pk = res_id) path = os.path.join(BASE_DIR, 'uploads\\' + str(res_id) + '\\t.txt') p_values = parse_res.main(path) res = Results(generator = inp, pvalues = p_values) res.save(using = 'results') return redirect(req, 'result.html', {'res': res})
models.py
from django.db import models from django import forms from inputData.models import Input from django.contrib.postgres.fields import JSONField class Results(models.Model): generator = models.OneToOneField(Input, on_delete = models.CASCADE, primary_key = True) pvalues = JSONField()
Traceback:
Traceback (most recent call last):
File “C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py”, line 86, in _execute
return self.cursor.execute(sql, params)
The above exception (ОШИБКА: отношение “results_results” не существует
LINE 1: UPDATE “results_results” SET “pvalues” = ‘{“BIRTHDAY_SPACING…
^
) was the direct cause of the following exception:
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\core\handlers\exception.py“, line 34, in inner
response = get_response(request)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\core\handlers\base.py“, line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\core\handlers\base.py“, line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File ”A:\project\diehard\results\views.py“, line 27, in result
res.save(using = ’results')
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\base.py“, line 745, in save
self.save_base(using=using, force_insert=force_insert,
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\base.py“, line 782, in save_base
updated = self._save_table(
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\base.py“, line 864, in _save_table
updated = self._do_update(base_qs, using, pk_val, values, update_fields,
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\base.py“, line 917, in _do_update
return filtered._update(values) > 0
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\query.py“, line 771, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\sql\compiler.py“, line 1492, in execute_sql
cursor = super().execute_sql(result_type)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\models\sql\compiler.py“, line 1144, in execute_sql
cursor.execute(sql, params)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py“, line 100, in execute
return super().execute(sql, params)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py“, line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py“, line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py“, line 86, in _execute
return self.cursor.execute(sql, params)
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\utils.py“, line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ”C:\Users\Someone\Anaconda3\lib\site-packages\django\db\backends\utils.py“, line 86, in _execute
return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /results/91/
Exception Value: ОШИБКА: отношение ”results_results" не существует
база данных results создана в pgadmin. До этого я откатывался к своей начальной миграции модели Results.
Рецепт с очищением истории миграции и применением фальшивой миграции не помог.
python manage.py migrate --fake results zero python manage.py showmigrations >>>results [ ] 0001_initial python manage.py migrate --fake-initial
Объект класса Input сохранен в бд default и у моделей Input, Results связь один-ко-одному. То есть поле generator — это первичный ключ для модели Results.