my_app/openapi_server/impl/modelsImpl/supportModel.py
def insertCampaign(campaignInfo, user):
"""
insertCampaign
"""
dt_now = sfunc.getTimeNowStr()
mainImageUrl = "dummy"
stmt = insert(M_promotion_code).values(
period=campaignInfo.period,
# I added here
valid_days=campaignInfo.valid_days,
# I added here
)
result = db.session.execute(stmt)
In the code above, if valid_days is NULL, an error message appears saying “None is not of type ‘integer’ – ‘validDays'”.
This is how the model is set, so it should be possible to register NULL, but I don’t understand why this error occurs.
my_app/openapi_server/impl/models/m_promotion_code.py
class M_promotion_code(db.Model):
"""
promotion_table
"""
.
.
.
# I added here
valid_days = Column(INTEGER, nullable=True, comment="Valid Days")
# I added here
my_app//migrations/versions/1234_.py
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
.
.
.
op.add_column('m_promotion_codes', sa.Column('valid_days', sa.Integer(), nullable=True, comment='Valid Days'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
.
.
.
# ### end Alembic commands ###
I tried this but nothing change.
stmt = insert(M_promotion_code).values(
# ...other fields...
valid_days=campaignInfo.valid_days if campaignInfo.valid_days is not None else null(),
# ...other fields...
)
New contributor
A T is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3