四十八:数据库之alembic常用命令和经典错误的解决办法
时间:2021-07-01 10:21:17
帮助过:11人阅读
from sqlalchemy.ext.declarative import declarative_base# 数据库类型+连接数据库的插件,这里使用的pymysqlDB_URI = ‘mysql+pymysql://root:123456@127.0.0.1:3306/test‘engine = create_engine(DB_URI)Base = declarative_base(engine)class User(Base): __tablename__ = ‘user‘ id = Column(Integer, primary_key=True, autoincrement=True) username = Column(String(50), nullable=False) def __repr__(self): return f‘username: {self.username}‘Base.metadata.drop_all() # 删除所有表Base.metadata.create_all() # 创建表
alembic revision --autogenerate -m ‘first_commit‘



alembic upgrade head(最新) 、 alembic upgrade version(指定版本)


增加字段



减少字段



查看历史版本

查看当前版本

四十八:数据库之alembic常用命令和经典错误的解决办法
标签:技术 alt 删除 code image 库类 文件版本号 get 解决办法