lundi 4 mai 2015

Trying to create an SQLite table in Python 3 but it's saying I'm supplying too many values

I want to create a simple database that has a list of names and ID numbers. I want there to be 2 columns and a total of 4 rows - one for each person. The error I keep getting is:

OperationalError: table contacts has 2 columns but 4 values were supplied

Here is my code:

import sqlite3

conn = sqlite3.connect("test2.db")
cursor = conn.cursor()

cursor.execute('''CREATE TABLE IF NOT EXISTS contacts (name text, id_num text)''')

list = [('Taylor', '001'), ('Tory', '002'), ('Joe', '003'), ('Steve', '004')]

cursor.executemany("INSERT INTO contacts VALUES (?,?,?,?)", list)
conn.commit()

Aucun commentaire:

Enregistrer un commentaire