我有一个我构建的应用程序,它在本地计算机上运行完美但是一旦我部署它就会出现500服务器错误。 日志打印此错误...
ProgrammingError: relation "land_property" does not exist
LINE 1: ...video", "land_property"."featured_video_url" FROM "land_prop...
^
我认为这是我的postgres数据库的问题,因为我的本地机器运行应用程序与sqlite一样好。
我对编程很新,对django来说是全新的,所以感谢您的帮助
编辑: 这是我的models.py
from __future__ import unicode_literals
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from django.conf import settings
from django.db import models
from django.urls.base import reverse
from django.utils.translation import ugettext_lazy as _
class Feature(models.Model):
detail_text = models.TextField(_('Feature Details'))
class PropertyManager(models.Manager):
def get_random_properties(self):
return self.order_by('?')
class Property(models.Model):
parcel = models.TextField(_('Property Parcel'), null=True, blank=True)
property_size = models.CharField(
_('Property Size'), null=True, blank=True, max_length=255
)
contact_phone = models.CharField(
_('Property Contact Phone'), null=True, blank=True, max_length=255
)
features = models.ManyToManyField(Feature)
gallery_url = models.CharField(
_('Property Facebook Gallery URL'), null=True, blank=True,
max_length=255
)
price = models.CharField(
_('Property Price'), null=True, blank=True, max_length=255
)
# Media files
featured_image = models.FileField(blank=True)
featured_image_url = models.CharField(blank=True, null=True, max_length=255)
featured_video = models.FileField(blank=True)
featured_video_url = models.CharField(blank=True, null=True, max_length=255)
objects = PropertyManager()
def __unicode__(self):
return "Property {0} at {1}".format(self.id, self.parcel)
@property
def abs_uri(self):
return reverse('property_detail', args=[self.pk,])
@property
def extra_features(self):
return self.features.all()
def save(self, *args, **kwargs):
if self.featured_image or self.featured_video:
conn = S3Connection(
settings.AWS_ACCESS_KEY_ID,
settings.AWS_ACCESS_KEY_SECRET
)
bucket = conn.get_bucket(settings.AWS_S3_BUCKET)
k = Key(bucket)
if self.featured_image:
k.key = 'featured_images/{0}'.format(self.featured_image.name)
k.set_contents_from_file(self.featured_image.file)
k.make_public()
self.featured_image_url = k.generate_url(
expires_in=0, query_auth=False
)
self.featured_image = ''
if self.featured_video:
k.key = 'featured_video/{0}'.format(self.featured_video.name)
k.set_contents_from_file(self.featured_video.file)
k.make_public()
self.featured_video_url = k.generate_url(
expires_in=0, query_auth=False
)
self.featured_video = ''
super(Property, self).save(*args, **kwargs)
答案 0 :(得分:0)
经过多次反复试验后,我终于明白了。我的数据库结构看起来像这样......
if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
由于我只在服务器上设置了环境变量,所以它在sqlite db上运行了我的所有迁移。我将环境变量添加到我的本地计算机并重新运行迁移并且它有效。
非常感谢@Exprator的所有输入。
我现在遇到了另一个错误。当我尝试登录django admin时,它说" Forbidden"。有什么想法吗?