数据库练习(一)

This is a sample Python script.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

Press Shift+F10 to execute it or replace it with your code.

Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

class Config:
ENV = ‘development’
DEBUG = True
SQLALCHEMY_DATABASE_URI =‘mysql+pymysql://root:root@127.0.0.1:3306/students?charset=utf8’
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = True
SQLALCHEMY_ECHO = True
SECRET_KEY = ‘abcdasa’

app = Flask(name)
app.config.from_object(Config)

db = SQLAlchemy()
db.init_app(app)

class Student(db.Model):
tablename = ‘tb_student’
# 字段类型
# 字段类型
id = db.Column(db.Integer,autoincrement=True, primary_key=True,comment=‘用户名’)
name = db.Column(db.String(64), unique=True)
sex = db.Column(db.Boolean,default=True, comment=‘性别’)
age = db.Column(db.Integer,nullable=True,comment=‘年龄’)
email = db.Column(db.String(128),unique=True,comment=‘邮箱地址’)
money = db.Column(db.Numeric(8,2),default=0,comment=‘钱包’)
# 模型方法
def repr(self):
return “%s %s” % (self.id, self.name)

class Teacher(db.Model):
# 表结构声明
id = db.Column(db.Integer,primary_key=True, comment=‘ID’)
name = db.Column(db.String(64),unique=True,comment=‘姓名’)
option = db.Column(db.Enum(“讲师”,“助教”, “班主任”),default=“讲师”,comment=“角色”)
def repr(self):
return ‘Teacher:%s’ % self.name

def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f’Hi, {name}’) # Press Ctrl+F8 to toggle the breakpoint.

Press the green button in the gutter to run the script.

if name == ‘main’:
with app.app_context():
db.create_all()
print_hi(‘PyCharm’)

See PyCharm help at https://www.jetbrains.com/help/pycharm/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值