I have a class shown below:
class Account(db.Model, flask_login.UserMixin):
__tablename__ = 'account'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(75))
username = db.Column(db.String(50))
password = db.Column(db.String(250))
admin = db.Column(db.Boolean)
def __init__(self, email='', username='', password='', admin=None):
self.email = email
self.username = username
self.password = password
self.admin = admin
def __repr__(self):
return '<Account %r>' % self.username
When I create an account through a form, the admin attribute will be None
. However when I access the database and try to manually set it to True
, the attribute will update but when I access the database again, the attribute is None
It's super annoying.
Here is what I execute on the console:
account = Account.query.get(1)
account.admin = True
db.session.commit()
db.admin ----> True
exit()
#restart again
account = Account.query.get(1)
account.admin ----> None
What am I doing wrong?