sqlalchemy.exc.IntegrityError: (mysql.connector.errors.IntegrityError) 1062 (23000): Duplicate entry ‘1@qq.com’ for key ‘email’
[SQL: UPDATE cms_user SET email=%(email)s WHERE cms_user.id = %(cms_user_id)s]
[parameters: {‘email’: ‘1@qq.com’, ‘cms_user_id’: 3}]
修改数据库用户的时候报错。
根据错误提示,官网的解释:
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.
This error is a DBAPI Error and originates from the database driver (DBAPI), not SQLAlchemy itself.
检查了数据库,没有建立外键,查看模型的设置,发现email字段是唯一的,而修改的邮箱与数据库中已有的数据冲突,导致修改失败。
解决办法:
1、将email设置成一个与数据库中不一样的
2、修改模型中的字段,取消unique