You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
I have an SQLAlchemy table with one primary key column and one column with a default value (sqlalchemy.sql.functions.now()).
Because both columns in the table have a default value (from a sequence or the PostgreSQL now() function), I should be able to insert a row without a values argument, or with an empty mapping, e.g. database.execute(table.insert()) or database.execute(table.insert(), values={}). But inserting a row either way raises a NotNullViolationError:
asyncpg.exceptions.NotNullViolationError: null value in column "id" of relation "post" violates not-null constraint
DETAIL: Failing row contains (null, null).
It seems that a default value isn't being generated for the ID column, which is violating its not-null constraint.
The exception isn't raised and the row is inserted if I pass a value, e.g. database.execute(table.insert(), values={"posted_at": datetime.datetime.now()}), but that defeats the purpose of defining a default value in the database schema.
I have an SQLAlchemy table with one primary key column and one column with a default value (
sqlalchemy.sql.functions.now()).Because both columns in the table have a default value (from a sequence or the PostgreSQL
now()function), I should be able to insert a row without avaluesargument, or with an empty mapping, e.g.database.execute(table.insert())ordatabase.execute(table.insert(), values={}). But inserting a row either way raises aNotNullViolationError:It seems that a default value isn't being generated for the ID column, which is violating its not-null constraint.
The exception isn't raised and the row is inserted if I pass a value, e.g.
database.execute(table.insert(), values={"posted_at": datetime.datetime.now()}), but that defeats the purpose of defining a default value in the database schema.