My problem is somewhat similar to what is discussed here: Django automatically create primary keys for existing database tables
But instead of simple python manage.py inspectdb
I did python manage.py inspectdb --include-views
.
And my problem is with those classes based on views- I get Error 1054, ("Unknown column 'station_measurements_with_data.id' in 'field list'")
I've tried to simply add id = models.IntegerField(primary_key=True)
to the model, but no joy.
The model class looks like this:
class StationMeasurementsWithData(models.Model):
station_id = models.IntegerField()
measurement_id = models.IntegerField()
time_utc = models.DateTimeField()
pollution_name = models.CharField(max_length=45)
measurement_value = models.FloatField(blank=True, null=True)
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'station_measurements_with_data'
And the view data int the database looks like this:
# station_id, measurement_id, time_utc, pollution_name, measurement_value
955, 87318, 2012-01-01 02:00:00, pm2.5, 73
955, 87318, 2012-01-01 02:00:00, pm10, 308
956, 87319, 2012-01-01 02:00:00, pm2.5, 123
956, 87319, 2012-01-01 02:00:00, pm10, 152
957, 87320, 2012-01-01 02:00:00, pm2.5, 163
957, 87320, 2012-01-01 02:00:00, pm10, 198
If any column contained unique values I would just make it a primary key, but there isn't one. What should I do in this case?