Mariadb: внешний ключ всегда NULL - PullRequest
0 голосов
/ 26 февраля 2020

Il пытается создать внешний ключ в моей таблице s2. Я видел, что столбец id_s1 в моей таблице s2 всегда 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()
...