python-3.x - Mariadb:外键始终为 NULL
问题描述
我试图在我的表 s2 中创建外键。我看到我的表 s2 中的列 id_s1 始终为 NULL。我的代码如下:
cursor.execute("CREATE TABLE s1 (
id binary(8) primary key, Cp VARCHAR(10),
name varchar(10),
capital VARCHAR(10)); »)
cursor.execute("INSERT INTO s1 (id, Cp, name, capital)
VALUES (uuid(),%s, %s, %s )", (x1, x2, x3))
cursor.execute("CREATE TABLE s2 (
id binary(8) primary key,
Dpt VARCHAR(10),
Nation VARCHAR(10),
id_s1 binary(8),
FOREIGN KEY(id_s1) REFERENCES s1(id)); »)
cursor.execute("INSERT INTO s2 (id, Dpt, nation)
VALUES (%s, %s, %s)", (x1, x2, x3))
cnx.commit()
解决方案
推荐阅读
- mysql - 不是唯一的表/别名 wp-query
- javascript - 仅使用输入字段上传文件 - React Hook Form
- sql - hive sql将不同的表连接为结构数组
- html - Primefaces p:datatable sortBy无法正常工作
- clojure - 在 Clojure 中复制 Java peek 流方法
- docker - 你如何让 WebStorm 将 Dockerfile.dev 文件突出显示为 Dockerfile?
- refresh - 谷歌浏览器更新到版本 85 后静默刷新不起作用
- c++ - 在 Windows 上构建 pytorch 时出现 C1001 内部编译器错误
- javascript - 当鼠标悬停在 DOM 中的特定元素上时订阅
- flutter - Flutter - 如何将图表保存为设备中的图像或发送到服务器?