SQLAlchemy boolean value is None SQLAlchemy boolean value is None python python

SQLAlchemy boolean value is None


You have to set a default value otherwise None/NULL is used:

is_active = Column(Boolean, unique=False, default=True)

You wanted to do this in __init__ but you used is_active = True (a local variable) instead of self.is_active = True.


If you're using Flask-SQLAlchemy, you can use this command to create a server side default.

from sqlalchemy.sql import expressionactive = db.Column(db.Boolean, server_default=expression.true(), nullable=False)

This will create a default value on the database so anyone can write to it and the DB will have the default value.


is_active = Column(Boolean, server_default='t', default=True)