我正在使用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...
^
有人可以帮我吗?先谢谢
答案 0 :(得分:1)
您重置了项目中的所有文件。但是迁移历史记录保存在django_migrations表中。您还必须清理此表。 您是否已删除&#39;迁移&#39;您应用中的文件夹?