sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError)

python sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError) (1217, 'Cannot delete or update a parent row: a foreign key constraint fails')

使用flask_sqlalchemy创建数据库表时,报上述错误。原来是以下代码问题

user_account = db.Column(db.String(20), unique=False, nullable=False)

在创建数据表的外键引用必须是唯一的,否则不能确定外键指向。将代码修改如下即可

user_account = db.Column(db.String(20), unique=Truenullable=False)

你可能感兴趣的:(sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError))