时间:2021-07-01 10:21:17 帮助过:19人阅读
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()
sqlalchemy操作mysql
标签:pymysql rom primary 操作 create meta ada class root