When I use sa.Identity() in my table - sqla-history version table doesnt work with alembic
AbdealiLoKo opened this issue · 1 comments
AbdealiLoKo commented
If I have a table like:
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Article(Base):
__tablename__ = 'article'
id = sa.Column(sa.Integer, sa.Identity(), primary_key=True, autoincrement=True)
name = sa.Column(sa.String(255))
When I add __versioned__ = {}
to add it to sqla-history, I get the following issue with alembic autogeneration:
sqlalchemy.exc.ArgumentError: A column with an Identity object cannot specify autoincrement=False
AbdealiLoKo commented
It looks like the issue is related to when sqla-history is copying the table, the autoincrement
flag is being set to False
But then sqlalchemy cannot handle cases where autoincrement
is False + Identity()
is provided
https://github.com/corridor/sqlalchemy-history/blob/v2.0.0/sqlalchemy_history/table_builder.py#L30
And the confusing is arising because:
- In sqlite, MySQL, mssql -
autoincrement=True
is needed - In oracle -
Identity()
is needed
as per the documentation: https://docs.sqlalchemy.org/en/20/dialects/oracle.html#specifying-generated-as-identity-oracle-12-and-above