【问题标题】:Django, new model raises error when trying to access the serverDjango,新模型在尝试访问服务器时引发错误
【发布时间】:2020-04-06 09:15:13
【问题描述】:

我有以下模型,这是新的:

from django.db import models


class Point(models.Model):
    latitude = models.FloatField(verbose_name="Latitude",
                                 blank=False)
    longitude = models.FloatField(verbose_name="Longitude",
                                  blank=False)
    elevation = models.FloatField(verbose_name="Location's Elevation",
                                  blank=True)


class Location(Point):
    created_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='create')

    location_name = models.TextField(verbose_name="Location Name",
                                     blank=False,
                                     unique=True,)
    location_info = models.ForeignKey(Point,
                                      related_query_name='new_location',
                                      on_delete=models.CASCADE,
                                      blank=False,
                                      )

我运行了 makemigrations 和 migrate 并且没有遇到任何错误。 运行服务器时出现以下错误:

ProgrammingError at /points/
column NewLocationModel_location.point_ptr_id does not exist
LINE 1: ...location" INNER JOIN "NewLocationModel_point" ON ("NewLocati...

【问题讨论】:

  • 您的服务器是否使用了正确的数据库?错误信息很清楚:NewLocationModel_location.point_ptr_id does not exist
  • 该错误表明您没有运行makemigrations并正确迁移,因为您的db中不存在Point的FK。
  • @Hoenie 你是对的,抱歉,没注意到。
  • 别担心,会发生的 ;-)

标签: python django django-models


【解决方案1】:

错误信息表明该列不存在。

column NewLocationModel_location.point_ptr_id does not exist

确保您使用的是正确的数据库...

【讨论】:

    猜你喜欢
    • 2019-12-12
    • 2022-01-24
    • 2015-06-16
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    相关资源
    最近更新 更多