This is my first python app, I have been struggling to get migrations working correctly with flask and sqlalchemy. I finally got that working but now when I run the application, I get an error when I add an object to the table that was modified with the migration code. This is the view the exception is thrown on db.session.add(newTag)
def put(self):
json_data = request.get_json(force=True)
foo = json_data['foo'] if 'foo' in json_data else ''
bar = json_data['bar'] if 'bar' in json_data else ''
baz = json_data['baz'] if 'baz' in json_data else ''
try:
boo = parse(json_data['boo'])
far = parse(json_data['far'])
except:
return jsonify(result='Invalid date')
faz = json_data['faz'] if 'faz' in json_data else ''
if faz == '':
return jsonify(result="faz is missing")
newTag = Tags(faz, baz, foo, bar, boo, far, True)
db.session.add(newTag)
db.session.commit()
return {'Success, tag' + str(newTag.id) + ' created'}
My model looks like this
class Tags(db.Model):
id = db.Column(db.Integer, primary_key=True)
faz = db.Column(db.String(255))
foo = db.Column(db.Integer)
bar = db.Column(db.Integer)
baz = db.Column(db.Integer)
boo = db.Column(db.DateTime)
far = db.Column(db.DateTime)
status = db.Column(db.Boolean)
def __init__(self, faz, foo, bar, baz, boo, far, status):
self.faz = faz
self.foo = foo
self.bar = bar
self.baz = baz
self.boo = boo
self.far = far
self.status = status
I am not sure if any further detail is needed to assist me. I have put SQLALCHEMY_TRACK_MODIFICATIONS = False in the config.py file that contains my SQLALCHEMY_DATABASE_URI.