Closed Mr-Clear closed 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.
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 PostgreSQL docker container.
docker-compose.yaml
:Create table:
*Create model code:
python -m pwiz -e postgresql -u postgres -H localhost -P postgres > db_schema.py
Output:
As you can see, the column
id
is not represented in classTest
. When I create the table withoutCONSTRAINT test_pkey PRIMARY KEY (id)
, it works as expected.Peewee version: 3.17.1 PostgreSQL version: 16.2 Python version: 3.11.8