当前位置:网站首页>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 ?????
边栏推荐
- 关于NAND FLASH解扣的认识
- 强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
- be based on. NETCORE development blog project starblog - (13) add friendship link function
- VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
- Run PowerShell script prompt "because running script is prohibited on this system" solution
- 有人碰到过这种情况吗,oracle logminer 同步的时候,clob字段的值丢失
- Circular linked list--
- localtime居然不可重入,踩坑了
- First intention is the most important
- ustime写出了bug
猜你喜欢

路由基础之OSPF LSA详细讲解

【邂逅Django】——(二)数据库配置

Fundamentals of number theory and its code implementation

leetcode:226. 翻转二叉树【dfs翻转】

Manage nodejs with NVM (downgrade the high version to the low version)
![[encounter Django] - (II) database configuration](/img/13/9512c1e03349092874055771c3433d.png)
[encounter Django] - (II) database configuration

Ikvm of toolbox Net project new progress

redis探索之缓存一致性

手机便签应用

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
随机推荐
leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
SQLAlchemy在删除有外键约束的记录时,外键约束未起作用,何解?
Huawei interview question: Recruitment
[20220605] Literature Translation -- visualization in virtual reality: a systematic review
木架的场景功能
Perl 5.10.0 installation package download
下半年还有很多事要做
微信模拟地理位置_伪装微信地理位置
ASP.NET Core 6 从入门到企业级实战开发应用技术汇总
redis探索之缓存一致性
Tencent security and KPMG released a regulatory technology white paper to analyze the "3+3" hot application scenarios
localtime居然不可重入,踩坑了
Good luck brought by years of persistence
华为面试题: 招聘
Operations related to sequence table
题目 1004: 母牛的故事(递推)
基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
Compile and debug net6 source code
Scene function of wooden frame
redis探索之缓存击穿、缓存雪崩、缓存穿透