赞
踩
1、pip install sqlacodegen
pip install pymysql
在/usr/lib/python/site-packages/sqlacodegen/main.py中添加:
import pymysqlpymysql.install_as_MySQLdb()
2、创建review_models.sh文件,在文件中添加:
#!/usr/bin/env bash
sqlacodegen --noviews --noconstraints --outfile=models.py mysql://iips:iips@192.168.1.200:3306/iips
3、执行上面shell文件,将在当前目录下输出models.py,数据库iips中的表结构将转换成为sqlalchemy可操作的类对象,如下:
# coding: utf-8 from sqlalchemy import Column, DateTime, Integer, String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() metadata = Base.metadata class TBuilding(Base): __tablename__ = 't_building' id = Column(Integer, primary_key=True) building_code = Column(String(20), nullable=False, unique=True) land_code = Column(String(20), nullable=False, index=True) building_name = Column(String(40)) building_area = Column(Integer) rent_area = Column(Integer) one_floor_area = Column(Integer, nullable=False) total_floors = Column(Integer, nullable=False) floor_hight = Column(Integer, nullable=False) loadbearing = Column(Integer, nullable=False) status = Column(Integer, nullable=False) structure = Column(String(40))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。