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,520 points
12,317 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
• 58,100 points
so after the fake migration, I ran a real migration.

very helpful! Thankssss!
thanks a lot buddy

Related Questions In Python

+1 vote
1 answer

Error:Getting Site Matching Query Does Not Exist Error after creating django admin

Hello @kartik, The Site object for your Django project is ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
12,491 views
0 votes
1 answer
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
• 69,220 points
13,624 views
0 votes
3 answers

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

NameError: name 'xx' is not defined Python knows ...READ MORE

answered Mar 19, 2020 in Python by rahul
• 360 points
42,478 views
0 votes
1 answer

Error:Python3.4 can't install mysql-python

Hello @kartik, You can resolved this by the ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,880 points
2,097 views
0 votes
0 answers

AWS: can't connect to RDS database from my machine

When I tried to debug the code ...READ MORE

Apr 9, 2022 in Others by Kichu
• 19,050 points
774 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
• 58,100 points
1,699 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
• 58,100 points
20,244 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
• 58,100 points
5,665 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP