Django Postgres使迁移错误

时间:2018-04-07 11:26:40

标签: python django postgresql

我刚从本地部署了一些代码到生产服务器上。我已经使用django应用程序设置了一个postgres数据库。问题是我跑的时候:

$ python3 /usr/Apps/manage.py makemigrations

我收到以下错误

##################################################
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "api_neli_report" does not exist
LINE 1: ...ort"."price", "api_neli_report"."prediction" FROM "api_neli_

api_neli_report 是我设置的模型,尚未迁移,因为我无法在不收到错误的情况下进行迁移。

知道如何解决这个问题吗?

另见模特:

from django.db import models

# Create your models here.

class SSALi_Report(models.Model):

    date = models.DateField()
    ticker = models.CharField(max_length=10,default='NA')
    market = models.CharField(max_length=250,default='NA')

    price = models.FloatField()
    prediction = models.FloatField()



    def __str__(self):
        return str(self.date) + " - " + str(self.ticker)

class NELi_Report(models.Model):

    date = models.DateField()
    ticker = models.CharField(max_length=10,default='NA')
    market = models.CharField(max_length=250,default='NA')

    price = models.FloatField()
    prediction = models.FloatField()

请注意该模型正在我的本地工作

另见我的资源模型:

# Logic/resources.py

from tastypie.resources import ModelResource
from api.models import SSALi_Report
from api.models import NELi_Report
from tastypie.authorization import Authorization
class SSALi_Resource(ModelResource):
    class Meta:
        queryset =  SSALi_Report.objects.all()
        print("#"*50)
        print(queryset)
        resource_name = 'SSALi_Report'
        authorization = Authorization()

class NELi_Resource(ModelResource):
    class Meta:
        queryset =  NELi_Report.objects.all()
        print("#"*50)
        print(queryset)
        resource_name = 'NELi_Report'

我本地的表格

 Schema |            Name            | Type  |  Owner   
--------+----------------------------+-------+----------
 public | api_neli_report            | table | postgres

1 个答案:

答案 0 :(得分:0)

因此,解决这个问题的唯一方法是将本地数据库导出为SQL并将其导入生产数据库。这不是我想要的方式,但它完成了工作。