Skip to content

Support for SQLAlchemy Identity object #359

Open

Description

@duxnp

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

Activity

  1. added 2 commits that reference this issue on Jan 27, 2026
  2. added
    pinned
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pinned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions