当我试图将数据保存到数据库(位置)时,我收到http 500错误。我跟踪了与我的数据库相关的错误(在Mac上的Postgres.app上运行)。
控制台输出以下错误:
column "place" of relation "corkd_corkd" does not exist LINE 1: INSERT INTO "corkd_corkd ("user_id", "place", "drink_id") V...
我的模特是:
from django.contrib.gis.db import models
from django.contrib.auth.models import User
class corkd(models.Model):
user = models.ForeignKey(User)
place = models.PointField()
drink = models.ForeignKey('corkd.drink')
objects = models.GeoManager()
class drink(models.Model):
drink = models.CharField(max_length=20)
我的观点如下:
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.contrib.auth.models import User
from corkd.models import *
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.gis.geos import GEOSGeometry, Point
from django.views.decorators.csrf import csrf_exempt
import json
def bottlepopper(request):
if not request.user.is_authenticated():
#Redirects to start
HttpResponseRedirect('/accounts/login/')
return render_to_response('bottlepopper.html', context_instance=RequestContext(request))
def newPop(request):
print request.body
print request.user
lol = "testi"
if not request.user.is_authenticated():
return HttpResponse("Not authenticated")
elif request.method =="POST":
returned = json.loads(request.body)
Place = Point(returned['lat'], returned['lng'])
dummy = drink.objects.get()
print "testi"
try:
pop = corkd(user=request.user, place=Place, drink=dummy)
print lol
print pop
print dummy
pop.save()
return HttpResponse("Choff")
except Exception as exce:
print type(exce)
print exce
else:
return render_to_response('bottlepopper.html', context_instance=RequestContext(request))
我尝试使用正确的扩展创建新数据库,但我仍然坚持这一点。非常感谢帮助。