Django and Pipelinedb: Programming Error: column <database_name>.location_id does not exist

144 Views Asked by At

I'm working on a project using Django and postgresdb with streaming data coming in using pipelinedb. A sync script is running this. Everything is Dockerized.

The data is updated every 60 seconds on the test server.

I added this field to the model:

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

And for reference, here are both the Weather and Location models:

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

When I start up the server, everything is fine. Through the admin page (Django's default admin page) I can navigate to the weather_stats_mrel page in an attempt to view the data coming in.

Once Pipelindb updates the table, however, I get this error when I try to view the page:

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...
                                                             ^

From what I understand, Django should be adding this field automatically, right? Or do I now need to add this table manually? Where would I put it in the model?

I've never had this problem before when using ForeignKeys, but then again, this is the first time I'm working with tables that are pre-generated before Django even touches it.

Is there a work-around for this problem? Has anyone even run into this before?

1

There are 1 best solutions below

0
Derek Nelson On

It looks like you have a continuous view named weather_stats. It is not possible to add columns to an existing continuous view, so unless you included location_id in the continuous view's definition, that column won't be there.