sqlalchemy-timescaledb
sqlalchemy-timescaledb copied to clipboard
Support columns from an abstract table
Columns from an abstract table are not supported:
class Model(Base):
__abstract__ = True
created_at = Column(
DateTime(timezone=True),
nullable=False,
default=datetime.datetime.now
)
class Data(Model):
__table_args__ = ({
'timescaledb_hypertable': {
'time_column_name': 'created_at'
}
})
Will trigger an exception:
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions._base.UnknownPostgresError'>: cannot create a unique index without the column "created_at" (used in partitioning)
[SQL:
SELECT create_hypertable(
'data',
'created_at',
chunk_time_interval => INTERVAL '7 days',
if_not_exists => TRUE
);
]
(Background on this error at: https://sqlalche.me/e/20/dbapi)
I also encountered this problem. After searching the documentation, I set my column as primary key and this error disappeared.