Newtt
Newtt

Reputation: 6200

Relation does not exist on Heroku

I'm facing an error on deploying an application to Heroku.

I have my model BannerImage as follows:

class BannerImage(models.Model):
    id = models.AutoField(primary_key=True)
    image = models.ImageField(upload_to='dynamic/img')
    image_title = models.CharField(max_length=300)

    def __unicode__(self):
        return self.image_title

Which I've called in the index view as follows:

def index(request):
    context = RequestContext(request)
    prods = Product.objects.filter(active__icontains='yes')
    images = BannerImage.objects.all()
    dictionary = {'prods': prods, 'image_new': images}
    return render_to_response('index.html', dictionary, context)

This runs perfect locally but on deploying to Heroku, it gives me the following error:

ProgrammingError at /
relation "Abstract_bannerimage" does not exist
LINE 1: ...image", "Abstract_bannerimage"."image_title" FROM "Abstract_...

where Abstract is the app name.

The full traceback is here:

Environment:


Request Method: GET
Request URL: http://abstractindia.herokuapp.com/

Django Version: 1.6.4
Python Version: 2.7.7
Installed Applications:
('django_admin_bootstrapped.bootstrap3',
 'django_admin_bootstrapped',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Abstract',
 'south',
 'djrill',
 'storages',
 's3direct',
 'shop')
Installed Middleware:
('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')


Template error:
In template /app/templates/index.html, error at line 41
   relation "Abstract_bannerimage" does not exist
LINE 1: ...image", "Abstract_bannerimage"."image_title" FROM "Abstract_...
                                                             ^

   31 :       </ul>


   32 :     </div><!-- /.navbar-collapse -->


   33 :   </div><!-- /.container-fluid -->


   34 : </nav>


   35 : </section>


   36 : <section class="alt-sec">


   37 :     <div class="container">


   38 :         <div class="col-xs-12 col-sm-12 col-lg-12 col-md-12">


   39 :             <div class="photo-gall">


   40 :             <div class="carousel-inner">


   41 :                  {% for img in image_new %} 


   42 :                 <div class="item active">


   43 :                   <img src="{{ img.image.url }}" alt="">


   44 :                 </div>


   45 :                 {% endfor %}


   46 :               </div>


   47 :             </div>


   48 :         </div>


   49 :         {% for prod in prods %}


   50 :             <div class="col-xs-12 col-sm-12 col-lg-4 col-md-4">


   51 :                 <div class="prod-container">


Traceback:
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/Abstract/views.py" in index
  16.     return render_to_response('index.html', dictionary, context)
File "/app/.heroku/python/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
  29.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  169.         return t.render(context_instance)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/base.py" in render
  840.                 bit = self.render_node(node, context)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/debug.py" in render_node
  78.             return node.render(context)
File "/app/.heroku/python/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  156.         len_values = len(values)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in __len__
  77.         self._fetch_all()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  854.             self._result_cache = list(self.iterator())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  220.         for row in compiler.results_iter():
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  713.         for rows in self.execute_sql(MULTI):
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  786.         cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  99.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py" in execute
  53.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /
Exception Value: relation "Abstract_bannerimage" does not exist
LINE 1: ...image", "Abstract_bannerimage"."image_title" FROM "Abstract_...
                                                             ^

I've tried dropping the Heroku db and running syncdb and migrate again but it didn't help.

Upvotes: 1

Views: 2416

Answers (2)

femeloper
femeloper

Reputation: 96

I had the same issue with one page of my website that used a particular model. This error was resolved by running: python manage.py migrate --run-syncdb

I saw some other StackOverflow comments which suggested running python manage.py makemigrations followed by python manage.py migrate which was ineffective as there were no changes to the model (and I had already ran these commands when setting up my postgresql db backend).

Upvotes: 3

mentor
mentor

Reputation: 21

python manage.py migrate --run-syncdb should do the job.

Upvotes: 2

Related Questions