Mariadb:外键始终为NULL

时间:2020-02-26 14:22:09

标签: python-3.x mariadb mysql-python

我试图在我的表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()

0 个答案:

没有答案
相关问题