标签:mode ati 怎么办 mod mys -- product 就是 pymysql
Python中想要自动生成 model文件可以通过 sqlacodegen这个命令来生成对应的model文件
sqlacodegen 你可以通过pip去安装:
pip install sqlacodegen
格式:
sqlacodegen mysql+pymysql://username:password@host/database_name > model.py
说明:
给 sqlacodegen 加一个 --table 的参数即可
????sqlacodegen --tables products mysql+pymysql://root:root@127.0.0.1/shopify > products.py
????ls
products.py
????cat products.py
# coding: utf-8
from sqlalchemy import CHAR, Column, String, Text, text
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Product(Base):
__tablename__ = 'products'
id = Column(INTEGER(16), primary_key=True)
title = Column(String(256), nullable=False, server_default=text("''"))
product_id = Column(INTEGER(16))
shop_url = Column(String(120))
body_html = Column(Text)
vendor = Column(String(64))
product_type = Column(String(64))
created_at = Column(CHAR(30))
updated_at = Column(CHAR(30))
handle = Column(String(256))
published_at = Column(CHAR(30))
template_suffix = Column(String(256))
tags = Column(String(256))
published_scope = Column(CHAR(10), nullable=False, server_default=text("'web'"))
????
标签:mode ati 怎么办 mod mys -- product 就是 pymysql
原文地址:https://www.cnblogs.com/yinguohai/p/11778488.html