当前位置:网站首页>When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
2022-07-01 12:44:00 【CSDN Q & A】
One 、 Environmental Science :pyqt5+python 3.7+SQLAlchemy 1.4.36+mysql 8.0
Two 、 The relevant table structure is as follows :
class maintenanceZone(Base): __tablename__ = "maintenanceZone" # Regional information __table_args__ = { "mysql_engine": "InnoDB", } id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True) cityName = sa.Column(sa.String(100), nullable=False ) countyName = sa.Column(sa.String(100), nullable=False)class maintainerInfo(Base): __tablename__ = "maintainerInfo" # Personnel information __table_args__ = { "mysql_engine": "InnoDB", } id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True) userName = sa.Column(sa.String(100), unique=True, nullable=False, comment=" Name of person ") userPhone = sa.Column(sa.String(20), unique=True, comment=" Contact number of personnel ") zoneID = sa.Column(sa.Integer(), sa.ForeignKey("maintenanceZone.id", ondelete="RESTRICT",onupdate="CASCADE"), comment=" Area ID") zoneinfo = relationship("maintenanceZone", backref=backref('maintainerInfo',order_by=id))3、 ... and 、 The relevant code is as follows :
zoneOne = session.query(maintenanceZone).filter(maintenanceZone.cityName == old_city,maintenanceZone.countyName == old_country).one()session.delete(zoneOne)session.commit()Four 、 database engine The code is as follows :
dburl = "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(dbIni["user"], dbIni["password"],dbIni["host"], dbIni["port"], dbIni["db"])engine = create_engine( url=dburl, max_overflow=0, pool_size=5, pool_timeout=20, pool_recycle=-1, )5、 ... and 、 Questions as follows :
1、 stay mysql8.0 in , adopt sql Language deletion maintenanceZone When recorded in the table , Will trigger foreign key constraints , Prompt cannot be deleted ;
2、 stay python Passed in code SQLAlchemy Delete maintenanceZone When the same record in the table , There's no hint , Delete directly !
SQLAlchemy Delete maintenanceZone When the table records , Foreign key constraint is not effective ?????
边栏推荐
- Share several tools for designing exquisite circuit diagrams
- Application of stack -- bracket matching problem
- ASTM D 3801 vertical burning test of solid plastics
- 题目 2612: 蓝桥杯2021年第十二届省赛真题-最少砝码(枚举找规律+递推)
- Huawei interview question: Recruitment
- Fatal error: execution: there is no such file or directory
- ustime写出了bug
- 编译调试Net6源码
- [Maui] add click events for label, image and other controls
- 网络socket的状态要怎么统计?
猜你喜欢

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

数据库之MHA高可用集群部署及故障切换

Mobile note application

redis探索之缓存击穿、缓存雪崩、缓存穿透

Stack-------

Logstash error: cannot reload pipeline, because the existing pipeline is not reloadable

《MATLAB 神经网络43个案例分析》:第40章 动态神经网络时间序列预测研究——基于MATLAB的NARX实现

用.Net Core接入微信公众号开发

Chained storage of queues

A hole in solder paste
随机推荐
There are still many things to be done in the second half of the year
使用BurpSuite对app抓包教程
使用nvm管理nodejs(把高版本降级为低版本)
leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
MHA high availability cluster deployment and failover of database
System test UI test summary and questions (interview)
R language builds a binary classification model based on H2O package: using H2O GBM build gradient hoist model GBM, use H2O AUC value of AUC calculation model
Ustime wrote a bug
用.Net Core接入微信公众号开发
天青色等烟雨
(mixed version 1) multiple TXT text to one table
Circular linked list--
Scene function of wooden frame
[brain opening] west tide and going to the world series
IOS interview
CPI教程-异步接口创建及使用
Application of stack -- bracket matching problem
Question d'entrevue de Huawei: recrutement
QT 播放器之列表[通俗易懂]