79446472

Date: 2025-02-17 20:02:52
Score: 1
Natty:
Report link

This is not a complete answer to the question but a workaround I found and will use.

What I did is I created this property:

from sqlalchemy import func

# tip: this can be decorated as a @property in a class
def next_value():
    v = User.query.with_entities(func.max(User.column)).scalar()
    return v+1 if v is not None else 0

Usage:

user1 = User() # NULL
user2 = User(column=next_value()) # next free value
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: roundedrectangle