I have to do some work with a SQL Database. I have done a bit of research on with video but I got very confused
Could you please explain to me how I insert python lists index into a SQL database?
I’m trying to make the Location a foreign key from its own table. This will allow for easier access in the future so that I can call all the cities from one country with a WHERE statement. I’m doing this so that I can scale this in the future to something else but I want to know how to do it with this example.
LocationID – United Kingdom = 1 France = 2 Denmark = 3 Germany = 4
London + LocationID1
This is how I want it to look.
This is what I have so far:
import sqlite3 Location = ["United Kingdom","Germany","France","Denmark"] Places = ["London","Tottenham","Munich","Paris","Frankfurt"] conn = sqlite3.connect("Location.db") c = conn.cursor() c.execute("INSERT INTO Places Location) conn.commit() conn.close()
This returns an error for me
I don’t know if I need to provide the database file. Just ask me if you need it to assist me
Source: Python Questions