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
• 14,960 points
348 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.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,100 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
• 65,810 points
629 views
0 votes
1 answer

Python error "NameError: name 'sr' is not defined"

I guess you are using speech_recognition module and missing ...READ MORE

answered Nov 28, 2018 in Python by Omkar
• 65,810 points
1,656 views
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
• 65,810 points
10 views
0 votes
1 answer

Tkinter “module not callable” error.

Tk() is a module and not a ...READ MORE

answered May 8 in Python by Yash
16 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,100 points
64 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
67 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,100 points
1,493 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,100 points
288 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.