#_coding:utf-8_
author = "toby"

import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String

engine = create_engine("mysql+pymysql://root:1qaz#[email protected]/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) #创建表结构