【发布时间】: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