Skip to content

Commit

Permalink
Fix not null constraint for primary keys when inserting using postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagovarela committed May 7, 2019
1 parent db549b0 commit 66a914a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions orm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ async def create(self, **kwargs):
)
kwargs = validator.validate(kwargs)

# Remove fields that are allowed to be NULL or auto incremented
kwargs = {
key: value
for key, value in kwargs.items()
if not (fields[key].allow_null and value is None)
}

# Build the insert expression.
expr = self.table.insert()
expr = expr.values(**kwargs)
Expand Down

0 comments on commit 66a914a

Please sign in to comment.