1、总结出错的问题
当我在用flask做项目的时候,需要创建表,创建表的时候,我用的是Flask-Migrate组件,直接用python manage.py init ,python manage.py migrate ,python manage.py upgrade这样的命令就可以创建表。
我的测试表结构是这样的
from sqlalchemy import Column, Integer, String, UniqueConstraint
from sqlalchemy_utils import ChoiceType from app import db class UserInfo(db.Model):
'''用户表'''
__tablename__ = "userinfo"
id = Column(Integer(), primary_key=True)
name = Column(String(32), index=True, nullable=False)
email = Column(String(32), unique=True)
__table_args__ = (
UniqueConstraint("id", "name", name="id_username"), # id和username联合唯一
{
"mysql_engine": "InnoDB",
"mysql_charset": "utf8"
}
) class Group(db.Model):
__tablename__ = "group"
id = Column(Integer(), primary_key=True)
name = Column(String(32))
__table_arg__ = {
"mysql_engine": "InnoDB",
"mysql_charset": "utf8"
} class Xuan(db.Model):
__tablename__ = 'xuan'
types_choices = (
(1,'欧美'),
(2,'日韩'),
(3,'老男孩'),
)
id = Column(Integer,primary_key=True,autoincrement=True)
name = Column(String(64))
types = Column(ChoiceType(types_choices,Integer()))
model
出错现象:
当我python manage.py upgrade的时候
执行命令的时候会自动生成这样的结构
解决办法:在没有python manage.py upgrade之前手动解决
然后再次python manage.py upgrade的时候就合适了。。