Error: persisting 'ProgrammingError: column does not exist'

0 votes

Models.py for 'Accomm':

class Accomm(models.Model):
    mapped_location=models.ForeignKey(Location,related_name='l_accomms',null=True,blank=True,on_delete=models.SET_NULL)
    description=models.CharField(max_length=1000,null=True,blank=True)
    creator=models.OneToOneField(accountmodels.UserProfileModel,related_name='u_creator',null=True,on_delete=models.SET_NULL,blank=True)
    slug_key=models.SlugField(unique=True)
    is_active=models.BooleanField(default=False)

Views.py:

def home(request):
    user = request.user
    accomm = Accomm.objects.annotate(img_count=models.Count('a_image')).filter(img_count__gte=1)[:6]
    return render(request, 'home.html', {'accomm':accomm})

Any other ideas besides the solutions proposed here?

Sep 28, 2018 in Python by bug_seeker
• 15,310 points
482 views

Full error:

Django Version: 1.11.7
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.gis',
 'django.contrib.humanize',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.staticfiles',
 'rest_framework',
 'accounts',
 'maps',
 'objects',
 'social_django']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'social_django.middleware.SocialAuthExceptionMiddleware']

Traceback:

    File "/Library/Python/2.7/site-packages/django/core/handlers/exception.py" in inner
      41.             response = get_response(request)

    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in _get_response
      187.                 response = self.process_exception_by_middleware(e, request)

    File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in _get_response
      185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

    File "/Users/jayt/project/main/views.py" in home
      21.     return render(request, 'home.html', {'accomm':accomm})

    File "/Library/Python/2.7/site-packages/django/shortcuts.py" in render
      30.     content = loader.render_to_string(template_name, context, request, using=using)

    File "/Library/Python/2.7/site-packages/django/template/loader.py" in render_to_string
      68.     return template.render(context, request)

    File "/Library/Python/2.7/site-packages/django/template/backends/django.py" in render
      66.             return self.template.render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render
      207.                     return self._render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in _render
      199.         return self.nodelist.render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render
      990.                 bit = node.render_annotated(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render_annotated
      957.             return self.render(context)

    File "/Library/Python/2.7/site-packages/django/template/loader_tags.py" in render
      177.             return compiled_parent._render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in _render
      199.         return self.nodelist.render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render
      990.                 bit = node.render_annotated(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render_annotated
      957.             return self.render(context)

    File "/Library/Python/2.7/site-packages/django/template/loader_tags.py" in render
      72.                 result = block.nodelist.render(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render
      990.                 bit = node.render_annotated(context)

    File "/Library/Python/2.7/site-packages/django/template/base.py" in render_annotated
      957.             return self.render(context)

    File "/Library/Python/2.7/site-packages/django/template/defaulttags.py" in render
      321.             if match:

    File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __nonzero__
      258.         return type(self).__bool__(self)

    File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __bool__
      254.         self._fetch_all()

    File "/Library/Python/2.7/site-packages/django/db/models/query.py" in _fetch_all
      1118.             self._result_cache = list(self._iterable_class(self))

    File "/Library/Python/2.7/site-packages/django/db/models/query.py" in __iter__
      53.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)

    File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
      894.             raise original_exception

    Exception Type: ProgrammingError at /
    Exception Value: column objects_accomm.description does not exist
    LINE 1: ...omm"."id", "objects_accomm"."mapped_location_id", "objects_a...
                                                             ^

1 answer to this question.

0 votes

Something I like to try when my migrations get wonky is a something like:

python manage.py makemigrations
python manage.py migrate --fake

So this will make it seem like you model has the added column, so from here I then cut and paste the model into a temporary file, save the models and run the migrations regularly which will remove all of the model. Then you paste the model back into models.py and run migrations one more time. This seems to work for me, there are probably better ways to manage this however I am relatively new to django as I am just completing my first big project in it. Really hope this helps, if not let me know and I may have something else for you!

answered Sep 28, 2018 by Priyaj
• 56,160 points

Related Questions In Python

0 votes
1 answer

Python argparse error "NameError: name 'file' is not defined"

The right datatype for destination in argpasrse module ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 67,120 points
967 views
0 votes
2 answers
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2 in Python by Omkar
• 67,120 points
17 views
0 votes
2 answers

Tkinter “module not callable” error.

This error statement TypeError: 'module' object is ...READ MORE

answered Jun 27 in Python by rahul
• 200 points
193 views
0 votes
1 answer

Host not allowed

Go to your project directory cd project cd project ALLOWED_HOSTS ...READ MORE

answered Aug 9, 2018 in AWS by Priyaj
• 56,160 points
89 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,790 points
106 views
0 votes
1 answer

ProgrammingError: not all arguments converted during string formatting

Sorted!!!! just found the solution, 1 - apparently ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 56,160 points
2,168 views
0 votes
1 answer

ProgrammingError: not all arguments converted during string formatting

Sorted!!!! just found the solution, 1 - apparently ...READ MORE

answered Sep 20, 2018 in Python by Priyaj
• 56,160 points
400 views