Insert using example form causing error "column "id" violates not-null constraint"

129 views
Skip to first unread message

Wanderson Santiago dos Reis

unread,
Jun 25, 2020, 12:14:44 PM6/25/20
to py4web
I've coded a new form based on "example form" (create_form action) but on submit cause the error: psycopg2.errors.NotNullViolation: null value in column "id" violates not-null constraint

The form is passing the correct vars data dict with id: None and to database as a null value.  The PostgreSQL sequence for auto increment the id field was working properly. PostgreSQL waiting a "DEFAULT" value to id generate the new primary key, but receiving null instead. I didn't found a workaround to solve this trouble. Maybe a pydal related issue.


Software info:
py4web 1.20200517.1
pydal 20200531.3
psycopg2-binary 2.8.5
PostgreSQL 11.8 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 8.1.0 (clang-802.0.42), 64-bit

Wanderson Santiago dos Reis

unread,
Jun 26, 2020, 12:02:42 AM6/26/20
to py4web
Tested workaround:  add to models.py for each table => db.table_name.id.writable=False

Massimo

unread,
Jul 1, 2020, 1:24:02 AM7/1/20
to py4web
Thanks. Patch applied.
Reply all
Reply to author
Forward
0 new messages