I want to set the default value of my SQLAlchemy postgres JSON column to an empty dictionary.
from sqlalchemy.dialects.postgresql import JSON
info = Column(JSON, default='{}')
info = Column(JSON, default={})
Neither of these work.
Using default=lambda: {} works. Credit goes to univerio in the comments.
The easiest way I've found to define a JSON not null (if applies) column with a default {}
value is (tested with SQLAlchemy 1.3.x):
info = db.Column(JSON, nullable=False, server_default='{}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With