时间:2021-07-01 10:21:17 帮助过:42人阅读
代码:
1 #!/usr/bin/env python 2 # encoding: utf-8 3 """ 4 @author: 侠之大者kamil 5 @file: Sqlalchemy_test1.py 6 @time: 16/4/11 下午10:41 7 """ 8 #from sqlalchemy import create_engine,Table,column,Integer,ForeignKey 9 from sqlalchemy import * 10 11 metadata = MetaData() 12 13 user = Table("user",metadata, 14 Column(‘id‘,Integer,primary_key=True), 15 Column(‘name‘,String(20)), 16 ) 17 18 color = Table("color",metadata, 19 Column(‘GUID‘,Integer,primary_key=True), 20 Column(‘code‘,String(20)),) 21 22 engine = create_engine("mysql+pymysql://myuser:lbk1992@xxxx.hk/python_one",max_overflow=5) 23 #python3 没有 mysqldb 支持,在此使用 pymysql. 24 metadata.create_all(engine) 25 26 metadata.clear()
SQLAlchemy 操作数据库
标签: