Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SQLAlchemy Identity object #359

Open
duxnp opened this issue Nov 11, 2024 · 0 comments
Open

Support for SQLAlchemy Identity object #359

duxnp opened this issue Nov 11, 2024 · 0 comments

Comments

@duxnp
Copy link

duxnp commented Nov 11, 2024

I'm using the Identity object from SQLAlchemy to specify the default value of primary keys.

    id: Mapped[int] = mapped_column(
        Integer,
        server_default=Identity(start=1, increment=1, always=True),
        primary_key=True,
        autoincrement=True,
    )

I can successfully create all tables by using Base.metadata.create_all. However when I try to insert a record into one of the tables, I receive an error when it tries to insert into the version table:
ORA-32795: cannot insert into a generated always identity column

I can work around this by specifying always=False for the id column. (This is not ideal since I'd rather use always=True to express the intent that I never plan to manually set a value for the primary key.) Now I can insert records and records are also successfully inserted into the version tables. However, I still have a problem with Alembic.

When I try using Alembic to autogenerate the revision for the tables I receive the following error:
sqlalchemy.exc.ArgumentError: A column with an Identity object cannot specify autoincrement=False

I'd appreciate any help anyone can offer.

Python 3.12.0
SQLAlchemy 2.0.36
SQLAlchemy-Continuum 1.4.2
Alembic 1.13.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant