I am developing a python application to insert data in my db, through a .csv file. However when importing the file the following error appears:
Warning: (1262, 'Row 1 was truncated; it contained more data than there were input columns')
result = self._query(query)
Basically for all lines in csv file. The data inside the file is as follows:
I can import that same way directly into the Workbench, but i would like to do it via the application.
Follow the code below:
from tkinter import *
import pymysql
import os
import os.path
tess = Tk()
def import_file():
conn = pymysql.connect(host='localhost', port=3306, user='root', password='', db='omnia')
print('connect successfull!')
if os.path.exists('C:/temp/teste.csv'):
statm = "LOAD DATA INFILE 'C:/temp/teste.csv' INTO TABLE testtable FIELDS TERMINATED BY ','"
cursor = conn.cursor()
cursor.execute(statm)
bt = Button(tess, text='browse file')
bt.place(x=10, y=10)
bt = Button(tess, text='import file', command=import_file)
bt.place(x=10, y=45)
tess.mainloop()
And also the table:
create table testTable(
n_id int not null auto_increment,
c_nome varchar(255),
c_depto varchar(255),
n_salario float,
primary key (n_id));

