import csv
import sqlite3
import os
if os.path.isfile('phones.db'):
os.remove ('phones.db')
conn= sqlite3.connect('phones.db')
db=conn.cursor()
db.execute("PRAGMA foreign_keys = ON")
db.execute ("""CREATE TABLE phones
(phoneID INTEGER PRIMARY KEY,
phone_colour TEXT,
phone_model INTEGER,
storage_size INTEGER,
price TEXT)""")
reader = csv.reader(open('phones.txt', 'r'), delimiter=',')
for row in reader:
to_db = [row[0], row[1], row[2], row[3], row[4] ]
db.execute('''INSERT INTO phones
(phoneID,phone_colour, phone_model,storage_size, price)
VALUES (?,?,?,?,?);''', to_db)
db.execute ("""CREATE TABLE customer
(clientID INTEGER PRIMARY KEY,
firstname TEXT,
surname TEXT,
age INTEGER,
number INTEGER,
email STRING)""")
reader = csv.reader(open('clients.txt', 'r'), delimiter=',')
for row in reader:
to_db = [row[0], row[1], row[2], row[3], row[4], row[5] ]
db.execute('''INSERT INTO customer
(clientID, firstname, surname, age, number,email)
VALUES (?,?,?,?,?,?);''', to_db)
db.execute ("""CREATE TABLE purchase
(purchaseID INTEGER PRIMARY KEY,
clientID INTEGER,
datepurchased TEXT,
timepurchased INTEGER,
phoneID INTEGER,
purchasedetails TEXT,
price INTEGER,
FOREIGN KEY(clientID)REFERENCES customer(clientID),
FOREIGN KEY(phoneID)REFERENCES phones(phoneID))""")
reader = csv.reader(open('clients.txt', 'r'), delimiter=',')
for row in reader:
to_db = [row[0], row[1], row[2], row[3], row[4], row[5], row[6] ]
db.execute('''INSERT INTO purchase
(purchaseID,clientID,datepurchased,timepurchased,phoneID,purchasedetails,price)
VALUES (?,?,?,?,?,?,?);''', to_db)
conn.commit
conn.close
What I have tried:
I'm trying to get my three tables to work but they aren't. This is the error I keep getting. Please help me.
IntegrityError: datatype mismatch
phones.py, line 37
No specific suggestions for this error (yet).
Let Thonny developers know
Click on the feedback link at the bottom of this panel to let Thonny developers know about your problem. They may add support for such cases in future Thonny versions.
Search the web
This is the csv file for table customer
0300,Charles,Clerk,21,0401273640,Charlieb@hotmail.com,
0301,Hunter,Parker,23,0490876598,Hunterparker@gmail.com,
0302,Zack,Davis,34,0412567456,Zdavis@hotmail.com,
0303,Gina,Porter,21,0489768990,PorterGina@outlook.com,
0304,Jane,Grey,42,0445673897,Janegrey@yahoo.com,
0305,Elijah,Casswell,34,0456487650,EJcasswell@gmail.com,
0306,Joshua,Bass,24,0498734523,Joshuabass@gmail.com,
0307,Rose,Colton,54,0410987603,RoseColton@gmail.com,
0308,Hazel,Stan,43,040913567543,Stanhazel@hotmail.com,
0309,Valentina,Brown,28,0445637864,ValBrown@yahoo.com,