当前位置:网站首页>SQLAlchemy在删除有外键约束的记录时,外键约束未起作用,何解?
SQLAlchemy在删除有外键约束的记录时,外键约束未起作用,何解?
2022-07-01 12:37:00 【CSDN问答】
一、环境:pyqt5+python 3.7+SQLAlchemy 1.4.36+mysql 8.0
二、相关表结构如下:
class maintenanceZone(Base): __tablename__ = "maintenanceZone" # 区域信息 __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" #人员信息 __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="人员姓名") userPhone = sa.Column(sa.String(20), unique=True, comment="人员联系电话") zoneID = sa.Column(sa.Integer(), sa.ForeignKey("maintenanceZone.id", ondelete="RESTRICT",onupdate="CASCADE"), comment="区域ID") zoneinfo = relationship("maintenanceZone", backref=backref('maintainerInfo',order_by=id))三、相关代码如下:
zoneOne = session.query(maintenanceZone).filter(maintenanceZone.cityName == old_city,maintenanceZone.countyName == old_country).one()session.delete(zoneOne)session.commit()四、数据库engine代码如下:
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, )五、问题如下:
1、在mysql8.0中,通过sql语删除maintenanceZone表中记录时,会触发外键约束,提示无法删除;
2、在python代码中通过SQLAlchemy删除maintenanceZone表中同一记录时,没有任何提示,直接删除!
SQLAlchemy删除maintenanceZone表记录时,外键约束未何未生效?????
边栏推荐
- Understanding of NAND flash deblocking
- How to install php7 and perform performance test using yum
- 队列的链式存储
- Sort out relevant contents of ansible
- 第十四章 信号(四)- 多进程任务示例
- Wechat simulated geographical location_ Camouflage wechat location
- Topic 1004: the story of cows (recursion)
- Need your own cognition
- 网络socket的状态要怎么统计?
- R语言基于h2o包构建二分类模型:使用h2o.gbm构建梯度提升机模型GBM、使用h2o.auc计算模型的AUC值
猜你喜欢

logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable

How to install php7 and perform performance test using yum

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

redis探索之缓存一致性

I wish you all a happy reunion
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

What are the PHP FPM configuration parameters

A hole in solder paste

VS Code 设置单击打开新文件窗口,不覆盖前一个窗口

Operations related to sequence table
随机推荐
IOS interview
leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]
Ansible相关内容梳理
使用BurpSuite对app抓包教程
What are the PHP FPM configuration parameters
ANSI/UL 94 VTM薄质材料垂直燃烧测试
kubernetes之ingress探索实践
第十四章 信号(四)- 多进程任务示例
The difference between memcpy and strcpy
Question d'entrevue de Huawei: recrutement
Chained storage of queues
STM32 project practice (1) introduction and use of photosensitive resistor
"Analysis of 43 cases of MATLAB neural network": Chapter 40 research on prediction of dynamic neural network time series -- implementation of NARX based on MATLAB
网络socket的状态要怎么统计?
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
AI matting tool
队列操作---
木架的场景功能
Eurake partition understanding
CPI教程-异步接口创建及使用