本文共 612 字,大约阅读时间需要 2 分钟。
#_coding:utf-8_
author = "toby"import sqlalchemy
from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, Stringengine = create_engine("mysql+pymysql://root:1qaz#EDC@127.0.0.1/db_ttr", encoding="utf-8", echo=True)
Base = declarative_base() #生成ORM基类
class Host(Base):
tablename = "hostinfo" #表名 id = Column(Integer, primary_key=True) #字段 (Integer是数据类型, primary_key=True 设置为主键) hostname = Column(String(32)) ip = Column(String(64))Base.metadata.create_all(engine) #创建表结构
本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/2048607
转载地址:http://ktxqa.baihongyu.com/