摘要:SQLAutocode
每次建立或修改資料表都需要建立對應程式碼,在網路上找了一套CodeGen 軟體,可以加速開發
1.要安裝前請先查詢 inflect 套件是否安裝
2.在PYTHON 目錄下 Scripts 下執行以下語法 ( Python Windows 安裝路徑 C:\Python27\Scripts )
sqlacodegen.exe mysql://root:@localhost:3306/test --o table.py #Demo方式是使用 MySql table.py 為檔案名稱
3.產生的程碼如下:
# coding: utf-8
from sqlalchemy import Column, DateTime
from sqlalchemy.dialects.mysql.base import _IntegerType, _StringType
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class DjangoMigration(Base):
__tablename__ = 'django_migrations'
id = Column(_IntegerType(11), primary_key=True)
app = Column(_StringType, nullable=False)
name = Column(_StringType, nullable=False)
applied = Column(DateTime, nullable=False)
class NewTable(Base):
__tablename__ = 'new_table'
SN = Column(_IntegerType(11), primary_key=True)
NAME = Column(_StringType)
SEX = Column(_StringType)
INSERT_TIME = Column(DateTime)
補充: