标签:命令 target base windows import tar roo -- rate
需要安装的包工具
创建表
1 from sqlalchemy import create_engine 2 from sqlalchemy.ext.declarative import declarative_base 3 from sqlalchemy import Column, Integer, String 4 5 DATABASE = { 6 ‘HOST‘: ‘localhost‘, 7 ‘USERNAME‘: ‘root‘, 8 ‘PASSWORD‘: ‘qwe123‘, 9 ‘PORT‘: ‘3306‘, 10 ‘DATABASE‘: ‘test‘, 11 ‘PARAMS‘: ‘utf8‘ 12 } 13 14 MYSQL_URL = ‘mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?{PARAMS}‘ 15 16 engine = create_engine(MYSQL_URL.format(**DATABASE)) 17 18 Base = declarative_base(engine) 19 20 21 class Test(Base): 22 __tablename__ = ‘test‘ 23 id = Column(Integer, autoincrement=True, primary_key=True) 24 name = Column(String(20)) 25 # password = Column(String(30)) 26 27 28 if __name__ == ‘__main__‘: 29 Base.metadata.create_all()
该配置等于model.py里面的mysql_url格式化后的结果(后面的参数去掉)
在 env.py
中设置,将target_metadata赋值成数据库的元数据(metadata)
如果执行 revision 有 import 报错,注意是否正确将当前项目目录添加到 sys.path 路径
迁移表
标签:命令 target base windows import tar roo -- rate
原文地址:https://www.cnblogs.com/ivy-blogs/p/11324482.html