【发布时间】:2015-10-24 16:44:51
【问题描述】:
所以我一直在整个互联网上阅读 Heroku 的开发中心,这里是 Stack Overflow,我不知道如何使用我的 Django 项目在 Heroku 上进行基本的工作。
我的主要问题是让 Postgres 数据库正常工作。我运行heroku run python manage.py syncdb,它说它会进行迁移,甚至创建一个超级用户,但是当我开始使用我部署的应用程序时,我得到了臭名昭著的“关系不存在”错误。
阅读我发现你必须在我的本地计算机上使用我的本地数据库运行python manage.py migrate,然后运行heroku run python manage.py syncdb 或heroku run python manage.py migrate。我很困惑是否真的是这种情况,以及当我使用 virtualenv 时是否仍然如此。
编辑:这是抛出“关系不存在错误”的相关视图以及使用的相应模型。
models.py
class Location(models.Model):
name = models.CharField(max_length=100)
route = models.ForeignKey('Route', null=True, blank=True)
client = models.CharField(max_length=50)
def __unicode__(self):
return u'%s, route: %s' % (self.name, self.route)
class Route(models.Model):
name = models.CharField(max_length=100)
client = models.CharField(max_length=50)
def __unicode__(self):
return u'%s' % self.name
serializers.py
from rest_framework import serializers
from .models import Route, Location
class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
fields = ('pk', 'client', 'name')
class RouteSerializer(serializers.ModelSerializer):
location_set = LocationSerializer(many=True)
class Meta:
model = Route
fields = ('pk', 'client', 'name', 'location_set')
views.py
from .models import Location, Route
from .serializers import RouteSerializer, LocationSerializer
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
class RouteList(APIView):
def get(self, request, format=None):
client = request.user.groups.all()[0]
routes = Route.objects.filter(client=client)
serializer = RouteSerializer(routes, many=True)
return Response(serializer.data)
【问题讨论】:
-
是的,我一开始就跟着信,导致我出现“关系不存在”的错误。
-
您遇到的错误不是因为部署问题。这是您的模型和/或视图的问题。请发布整个错误、相关模型和引发错误的视图。
-
我已经用相关代码编辑了我的原始帖子,但我也想知道为什么我的管理站点不包括我通过
admin.site.register(modelname)注册的模型?
标签: python django postgresql heroku