coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.18k stars 1.37k forks source link

PostgreSQL: pwiz doesn't generate field for primary key column #2875

Closed Mr-Clear closed 6 months ago

Mr-Clear commented 6 months ago

I tried to create model code for an existing PostgreSQL database and noticed that none of the primary key columns are present. This can be reproduced with this minimal example:

*Create model code: python -m pwiz -e postgresql -u postgres -H localhost -P postgres > db_schema.py

As you can see, the column id is not represented in class Test. When I create the table without CONSTRAINT test_pkey PRIMARY KEY (id), it works as expected.

Peewee version: 3.17.1 PostgreSQL version: 16.2 Python version: 3.11.8

coleifer commented 6 months ago

If the primary key is named "id" and is an auto-incrementing integer, then Peewee does not require you to declare it. In other words, if no primary key is explicitly specified, then an auto-incrementing primary key named "id" is assumed.