标签:pymysql rom primary 操作 create meta ada class root
from sqlalchemy import Column,String,create_engine,MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import pymysql
Base=declarative_base()
meta=MetaData()
class User(Base):
__tablename__=‘BUMEN‘
id=Column(String(20),primary_key=True)
name=Column(String(20))
engine=create_engine("mysql+pymysql://root:root@localhost:3306/haiku")
DBSession=sessionmaker(bind=engine)
session=DBSession()
User.metadata.create_all(bind=engine)
new_user=User(id=‘5‘,name=‘maker‘)
session.add(new_user)
session.commit()
session.close()
标签:pymysql rom primary 操作 create meta ada class root
原文地址:https://www.cnblogs.com/Haihong72H/p/14883875.html