0

Hi I'm trying to insert a foreign key when I create a table in pymysql but get an error. This is my code:

cur.execute('''CREATE TABLE IF NOT EXISTS artist(id int PRIMARY KEY NOT NULL AUTO_INCREMENT, full_name varchar,
FOREIGN KEY (id) REFERENCES song(artist_id))''')

cur.execute('''CREATE TABLE IF NOT EXISTS Song(id int PRIMARY KEY NOT NULL AUTO_INCREMENT, name varchar,
artist_id int, entry_date timestamp, entry_position int)''') 
Aurélien Gâteau
  • 4,010
  • 3
  • 25
  • 30
nis
  • 15
  • 4

2 Answers2

0

Assuming one artist can be the author of many songs, then this should be the other way around: the foreign key must be defined on the Song table and reference the Artist table.

Aurélien Gâteau
  • 4,010
  • 3
  • 25
  • 30
0

for the name and full name column you should add size as varchar(10) or some thing. and other error is you are tried to use id as primary and foreign key in artist table for that refer this stackoverflow question

Dulanga Heshan
  • 1,335
  • 1
  • 19
  • 36