Multiple timeseries in TimescaleDB using Django as framework

I’m pretty sure this is straightforward but I’m starting with timescaledb and I’m kind of lost with this.
I’m trying to setup multiple timeseries in timescaledb. The issue comes with different records having the same timestamp, for example

from django.db import models
from timescale.db.models.models import TimescaleModel
from .assets import Asset  

class TimeseriesData(TimescaleModel):
    time = models.DateTimeField(primary_key=True)
    asset = models.ForeignKey(Asset, on_delete=models.CASCADE)
    close_price = models.DecimalField(max_digits=10, decimal_places=2)
    volume = models.BigIntegerField()

    class Meta:
        unique_together = (('time', 'asset'),)  # Create a composite unique constraint

    

I might have different assets with the same time, and timescaledb requires time to be the primary key, so how can I work around this? It feels bad practice to create a new timescalemodel for each asset, is this how timescaledb suppose to be used?

I tried adding an id column as a primary key but it fails as timescaledb requires time to be the pk, I’m not sure what else to try.

2 Likes