1

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.

Newtt
  • 6,050
  • 13
  • 68
  • 106
  • did you checked in local server using `foreman start` ? – dhana Jun 22 '14 at 12:49
  • I think your app name should be lower case.see this http://stackoverflow.com/questions/3098681/is-there-a-naming-convention-for-django-apps – dhana Jun 22 '14 at 12:51
  • @dhana, that shouldn't matter as the app name convention was set by PyCharm when I created the project. And yes, locally using foreman start, it's working. – Newtt Jun 22 '14 at 21:09
  • check you really are using postgres: start shell and print django config databases ( from django.conf import settings; print settings.DATABASES; print settings.DATABASES['default'] ) – dani herrera Jun 22 '14 at 21:39
  • Here: `{'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, 'NAME': 'abstract', 'TEST_MIRROR': None, 'CONN_MAX_AGE': 0, 'TEST_NAME': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': 'localhost', 'USER': 'abstractroot', 'TEST_CHARSET': None, 'PASSWORD': 'password', 'PORT': ''}} ` – Newtt Jun 22 '14 at 21:46
  • When you run syncdb tables are created? I mean, syncdb inform to you about creating tables? You can see the tables in database ( heroku pg:psql ; \d ) – dani herrera Jun 22 '14 at 21:56
  • Yes, yes it does. I can access admin and even add rows to the table. – Newtt Jun 22 '14 at 21:57
  • @Newtt, this is very bizarre, django turn lowercase table names and in your trace appears as upper case. Try to force tablename in model, just for debug: `Meta: ; db_table = "abstract_bannerimage"` ( https://docs.djangoproject.com/en/dev/ref/models/options/#db-table ) – dani herrera Jun 22 '14 at 22:03

2 Answers2

3

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

femeloper
  • 96
  • 7
2

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

mentor
  • 21
  • 2