2

I am working with a Django application with Postgres Database.

My models are as follows:

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()

I made few changes to my schema.So i have to reset my DB.I reseted my DB and migrations and when im trying to run

python manage.py makemigrations

I am getting this error.I tried changing db and changing user and everything.I dont understand what made this error.

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...
                                                             ^

Can someone help me with this?Thanks in advance

1 Answer 1

2

You reseted all files in project. But migrations history saved in django_migrations tables . You also must clean this table. Are you deleted 'migrations' folder in your app?

Sign up to request clarification or add additional context in comments.

21 Comments

yes,but i cant find django_migrations table in postgres
can you show "Installed_apps" list in your settings.py file?
which version python and django?
python-2.7.12,django-1.10.6 ` INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'dynamicforms', 'accounts', 'surveys', ) `
These are My databases ` List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges myappnamedb | myappuser | UTF8 | en_IN | en_IN | postgres | postgres | UTF8 | en_IN | en_IN | template0 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_IN | en_IN | =c/postgres + | | | | | postgres=CTc/postgres `
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.