Skip to content

Commit

Permalink
Update sqlalchemy docs for prefer-identity rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWunderlich committed May 7, 2024
1 parent 9ac8190 commit 2956d05
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/docs/prefer-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ create table app.users

## solution for alembic and sqlalchemy

Built-in support for rendering of `IDENTITY` is not available yet,
As of sqlalchemy 1.4, use:

```python
# models.py
import sqlalchemy as sa

class User(BaseModel):
id = sa.Column(sa.Integer, sa.Identity(), primary_key=True)
```


For sqlalchemy 1.3 or prior built-in support for rendering of `IDENTITY` is not available yet,
however the following compilation hook may be used to replace occurrences of `SERIAL` with `IDENTITY`. See the [SQLAlchemy docs for more information](https://docs.sqlalchemy.org/en/13/dialects/postgresql.html#postgresql-10-identity-columns).

```python
Expand Down

0 comments on commit 2956d05

Please sign in to comment.