通过用户模型,对数据库进行增删改查操作
1.增加:
class User(db.Model):
__tablename__='user'
id=db.Column(db.Integer,primary_key=TabError,autoincrement=True)
username=db.Column(db.String(20),nullable=False)
password=db.Column(db.String(20),nullable=False)
user = User(username ='vixx',password='20120524' )
db.session.add(user)
db.session.commit()
2.查询:
user=User.query.filter(User.username =='vixx').first()
print(user.username,user.password)
3.修改:
user=User.query.filter(User.username =='vixx').first()
user.password='55555'
db.session.commit()
4.删除:
user=User.query.filter(User.username =='vixx').first()
db.session.delete(user)
db.session.commit()