I'm using sqlalchemy to create a table in mysql. I would like to have a JSON column, with a default value, but mysql doesn't allow literals to be the default value, only expressions.
If I create the column like this:
mycolumn = sqlalchemy.Column(
MutableDict.as_mutable(mysql.JSON),
server_default='{}'
)
The line for the column creation in the SQL query will look like this:
mycolumn JSON DEFAULT '{}'
But this doesn't work, I need this:
mycolumn JSON DEFAULT ('{}')
I also tried using json_object():
mycolumn = sqlalchemy.Column(
MutableDict.as_mutable(mysql.JSON),
server_default=func.json_object('{}', type_=JSON)
)
but this creates:
mycolumn JSON DEFAULT json_object()
and again, this doesn't work.
How can I put the default value into an expression , like mycolumn JSON DEFAULT ('{}')?
sqlalchemy.literal_column("('{}')")'(\'{}\')'mycolumn JSON NOT NULL DEFAULT ('{}')@snakecharmerbmycolumn json NOT NULL DEFAULT (_utf8mb4'{}')