I'm trying to add just a single value to mysql table from python. I've tried about five different methods but I still get the error saying that the other keys in my table aren't being passed values when I call insert. The thing is I don't want to insert any other values, just to one specific key. Heres the code I currently have, and thanks in advance for you help
cursor.execute("SELECT * FROM SONG")
result = cursor.fetchall()
sname = str(input("What is the name of the song you are looking for: "))
for row in result:
title = row[0]
if(title == sname):
sql = ("INSERT INTO USER (s_id) VALUES (%s)")
val = row[1]
cursor.execute(sql, (val,))
mysql.connector.errors.DatabaseError: 1364 (HY000): Field 'userid' doesn't have a default value
CREATE TABLE USER
(username VARCHAR(20),
userid CHAR(3),
a_id CHAR(3),
s_id CHAR(3),
PRIMARY KEY (userid),
FOREIGN KEY (a_id) REFERENCES ALBUM(a_id),
FOREIGN KEY (s_id) REFERENCES SONG(s_id));
CREATE TABLE PLAYLIST
(p_name VARCHAR(20),
p_id CHAR(3) NOT NULL,
userid CHAR(3),
s_id CHAR(3),
PRIMARY KEY (p_id),
FOREIGN KEY (userid) REFERENCES USER(userid),
FOREIGN KEY (s_id) REFERENCES SONG(s_id));