Flask Sqlalchemy Add Row Using Dynamic Column Name
I would like to add a row to an existing table but the column name is unknown. Earlier on in my script I have been able to use setattr() to update an existing entry and to query us
Solution 1:
To use variable keyword arguments (or kwargs
), a common workaround is the following:
retailer = 'gh'
sku = '8222868'
kwargs = { 'mainean': ean, retailer: sku }
retailer_add = SkuRetailer(**kwargs)
db.session.add(retailer_add)
Post a Comment for "Flask Sqlalchemy Add Row Using Dynamic Column Name"