【问题标题】:Django and Pipelinedb: Programming Error: column <database_name>.location_id does not existDjango 和 Pipelinedb:编程错误:列 <database_name>.location_id 不存在
【发布时间】:2018-09-01 13:32:01
【问题描述】:

我正在使用 Django 和 postgresdb 开发一个项目,其中流数据使用 pipelinedb 传入。同步脚本正在运行它。一切都是 Docker 化的。

测试服务器上的数据每 60 秒更新一次。

我将此字段添加到模型中:

location = models.ForeignKey('Location', related_name='assigned_sensor', on_delete=models.CASCADE, null=True)

作为参考,以下是 Weather 和 Location 模型:

class WeatherStatsMrel(models.Model):
    id = models.BigIntegerField(db_column='$pk', primary_key=True)
    loc = models.CharField(max_length=3, null=True)
    dat = models.DateField(blank=True, null=True, editable=True)
    tim = models.TimeField(blank=True, null=True, editable=False)
    aws = models.FloatField(blank=True, null=True, editable=False)
    awd = models.TextField(blank=True, null=True, editable=False)
    mws = models.FloatField(blank=True, null=True,editable=False)
    mwd = models.TextField(blank=True, null=True,editable=False)
    tmp = models.FloatField(blank=True, null=True,editable=False)
    hum = models.FloatField(blank=True, null=True,editable=False)
    r10 = models.FloatField(blank=True, null=True,editable=False)
    r60 = models.FloatField(blank=True, null=True,editable=False)
    rda = models.FloatField(blank=True, null=True,editable=False)
    rcu = models.TextField(blank=True, null=True,editable=False)
    rad = models.TextField(blank=True, null=True,editable=False)
    sun = models.TextField(blank=True, null=True,editable=False)
    location = models.ForeignKey('Location', related_name='assigned_sensor', on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = 'weather_stats_mrel'


    def __unicode__(self):
        return str({self.loc}, {self.dat}, {self.tim}, {self.aws}, {self.awd}, {self.mws}, {self.mwd}, {self.tmp}, {self.hum}, {self.r10}, {self.r60}, {self.rda}, {self.rcu}, {self.rad}, {self.sun})    

class Location(models.Model):
    id = models.AutoField(primary_key=True)
    abbreviated_name = models.CharField(max_length=3)
    full_name = models.CharField(max_length=25)

    def __str__(self):
        return self.abbreviated_name

当我启动服务器时,一切都很好。通过管理页面(Django 的默认管理页面),我可以在 attempt 中导航到 weather_stats_mrel 页面以查看传入的数据。

但是,一旦 Pipelindb 更新了表,当我尝试查看页面时出现此错误:

ProgrammingError at /admin/test_sensor_app/weatherstatsmrel/
column weather_stats_mrel.location_id does not exist
LINE 1: ...er_stats_mrel"."rad", "weather_stats_mrel"."sun", "weather_s...
                                                             ^
Request Method: GET
Request URL:    http://localhost:8000/admin/test_sensor_app/weatherstatsmrel/
Django Version: 2.1.1
Exception Type: ProgrammingError
Exception Value:    
column weather_stats_mrel.location_id does not exist
LINE 1: ...er_stats_mrel"."rad", "weather_stats_mrel"."sun", "weather_s...
                                                             ^

据我了解,Django 应该会自动添加此字段,对吧?还是我现在需要手动添加此表?我会把它放在模型的什么地方?

我以前在使用 ForeignKeys 时从来没有遇到过这个问题,但话又说回来,这是我第一次使用在 Django 接触之前预先生成的表。

是否有解决此问题的方法?有没有人遇到过这种情况?

【问题讨论】:

    标签: django postgresql pipelinedb


    【解决方案1】:

    看起来您有一个名为weather_stats 的连续视图。无法向现有连续视图添加列,因此除非您在连续视图的定义中包含 location_id,否则该列将不存在。

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 2015-06-01
      • 1970-01-01
      • 2016-01-19
      • 2022-07-08
      • 2021-06-10
      • 2021-10-26
      • 2016-02-14
      • 1970-01-01
      相关资源
      最近更新 更多