gpt4 book ai didi

django.db.utils.ProgrammingError : in DJango application

转载 作者:搜寻专家 更新时间:2023-10-30 23:35:33 25 4
gpt4 key购买 nike

我正在使用带有 Postgres 数据库的 Django 应用程序。

我的模型如下:

from django.db import models
from django.contrib.auth.models import User as UserModel
from dynamicforms.mangers import TextQuestionManager, MCQManager, IntegerQuestionManager
from django.db.models.fields.related import OneToOneRel
from django.contrib.postgres import fields as postgres_fields

Qtypes = [(1, "Multiple Choice Question"), (2, "Text Question"), (3, "integer Type Question")]
COMPS = [(True, 'Yes'), (False, 'No')]
SECTIONS = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]


class QuestionModel(models.Model):
qtype = models.IntegerField(null=False, choices=Qtypes)
text = models.TextField(max_length=500, null=False, blank=False)
description = models.TextField(max_length=1000, null=True, blank=True)
help_text = models.CharField(max_length=300, null=True, blank=True)
is_compulsory = models.BooleanField(default=True, null=False, choices=COMPS)

def __str__(self):
return self.text


class TextQuestionModel(QuestionModel):
nextQ = postgres_fields.ArrayField(models.IntegerField(blank=True, null=True), null=True, blank=True)
objects = TextQuestionManager()


class MCQModel(QuestionModel):
objects = MCQManager()

class Meta:
proxy = True


class IntegerQuestionModel(QuestionModel):
nextQ = postgres_fields.ArrayField(models.IntegerField(blank=True, null=True), null=True, blank=True)
objects = IntegerQuestionManager()

我对我的架构做了一些更改。所以我必须重置我的数据库。我重置了我的数据库和迁移,以及当我尝试运行时

python manage.py makemigrations

我收到这个错误。我尝试更改数据库和更改用户以及所有内容。我不明白是什么导致了这个错误。

Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace instance at 0x7fa990057998>
Traceback (most recent call last):
File "/opt/pycharm/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 553, in __call__
return self.original_func(*self.args, **self.kwargs)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/phani/Projects/Freewill/dynamicforms/admin.py", line 3, in <module>
from dynamicforms.forms import MCQFormAdmin, TextFormAdmin, IntegerFormAdmin
File "/home/phani/Projects/Freewill/dynamicforms/forms.py", line 6, in <module>
QS = [(i.id, i.text) for i in QuestionModel.objects.all()]
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/phani/Projects/Freewill/env/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "dynamicforms_questionmodel" does not exist
LINE 1: ..."dynamicforms_questionmodel"."is_compulsory" FROM "dynamicfo...
^

有人可以帮我吗?提前致谢

最佳答案

您重置了项目中的所有文件。但迁移历史保存在 django_migrations 表中。你还必须清理这张 table 。您是否删除了应用中的“迁移”文件夹?

关于django.db.utils.ProgrammingError : in DJango application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43060864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com