# 1. 导入SQLAlchemyfrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy import Column, Integer, String# 2.ORM 模型基类Base = declarative_base() # 相当于Django model# 3. 创建ORM对象class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(32), index=True)# 4.创建数据库连接from sqlalchemy import create_engineengine = create_engine('mysql+pymysql://root:root@127.0.0.1:3306/my_sqlalchemy?charset=utf8')# 5.# 去engine数据库中创建所有继承Base类的ORM对象Base.metadata.create_all(engine)
posted on 2019-02-15 20:04 阅读( ...) 评论( ...)