Heroku上不存在关系

时间:2014-06-22 12:05:50

标签: python django heroku

我在向Heroku部署应用程序时遇到错误。

我的模型BannerImage如下:

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

我在索引视图中调用的内容如下:

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)

这在本地运行完美,但在部署到Heroku时,它给出了以下错误:

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

其中Abstract是应用程序名称。

完整的追溯在这里:

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_...
                                                             ^

我尝试删除Heroku数据库并再次运行syncdbmigrate,但它没有帮助。

2 个答案:

答案 0 :(得分:1)

我在使用特定模型的网站页面上遇到了同样的问题。通过运行python manage.py migrate --run-syncdb

解决了该错误。

我看到了其他一些StackOverflow注释,这些注释建议先运行python manage.py makemigrations,然后再运行python manage.py migrate,这是无效的,因为模型没有更改(并且我已经在设置postgresql db后端时运行了这些命令)。

答案 1 :(得分:0)

python manage.py migrate --run-syncdb应该会做。