sqlalchemy.exc.IntegrityError: (IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`ooxx`.`friendship`, CONSTRAINT `friendship_ibfk_1` FOREIGN KEY (`user_id1`) REFEREN
fromsqlalchemy import create_engine,Table,Column,Integer,String,MetaData,ForeignKey 创建一个连接引擎 engine=create_engine("mysql+pymysql://root:a5230411@localhost:3306/test",echo=True) 我们将连接引擎放到engine里面方便后面使用。 create_engine("数据库类型+数据库驱动://数据库用户名:数据库密码@IP地址:...
连接MySQL数据库 在使用SQLAlchemy连接MySQL数据库之前,我们需要先准备好数据库的连接信息,包括数据库的地址、端口、用户名、密码等。假设我们要连接的数据库地址是localhost,端口是3306,用户名是root,密码是123456。我们可以通过如下代码来创建一个数据库引擎对象: ```python from sqlalchemy import create_engine engine...
fromsqlalchemyimportcreate_engine,Table,Column,Integer,String,MetaData,ForeignKey 创建一个连接引擎 engine=create_engine("mysql+pymysql://root:a5230411@localhost:3306/test",echo=True) 我们将连接引擎放到engine里面方便后面使用。 create_engine("数据库类型+数据库驱动://数据库用户名:数据库密码@IP地址:端...
pip3 install PyMySQL from sqlalchemy import create_engine from config import get_config from sqlalchemy import text if __name__ == '__main__': database = 'mysql' host = get_config(f'{database}', 'host') port = int(get_config(f'{database}', 'port')) username = get_config(...