2 yellow name yellow_name 于 2017.09.08 22:14 提问

sqlalchemy 同步数据库问题python
 from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('host':'mysql+pymysql://root:123456@localhost:3306/spider')
Base = declarative_base()


class BaseModel(Base):
    __abstract__ = True
    __metadata__ = MetaData(bind=engine)
    __table_arhs__ = {
        'mysql_engine': 'InnoDb',
        'mysql_charset': 'utf8mb4'
    }
    session = _Session(autocommit=False)


if __name__ == '__main__':
    BaseModel.__metadata__.create_all()

用 BaseModel.__metadata__.create_all() 不能同步数据库表 其中一个表类如下:

 from sqlalchemy import Column
from sqlalchemy.dialects.mysql import INTEGER, VARCHAR

from common.db import BaseModel


class CityModel(BaseModel):
    __tablename__ = 'city'

    id = Column(INTEGER, primary_key=True)
    name = Column(VARCHAR(64))

这样怎么同步mysql 自动生成表?
大佬们

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.09 23:53
Csdn user default icon
上传中...
上传图片
插入图片