I have the following column in SQLAlchemy:
name = Column(String(32), nullable=False)
I want that if no value is passed onto an insertion, it should enter a default value of either completely blank or if not possible, then default as NULL.
Should I define the column as :
name = Column(String(32), nullable=False, default=NULL)
Because in python NULL
object is actually None
Any suggestions?
If you want an empty string as default, you can:
name = Column(String(32), nullable=False, default='')
However, if you just do:
name = Column(String(32), nullable=True)
then the default value of the column will be a NULL.
Note that a NULL value indicates “unknown value”, and typically should not be confused with an empty string. If your application needs the concept of “unknown value”, then make your column nullable. If not, make it non-nullable and default to empty strings.
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