Afternoon Folks
I am trying to import a CSV into a table on MariaDB
The columns on the table are
MariaDB [snipeit]> show columns from locations;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | text | YES | | NULL | |
| city | varchar(191) | YES | | NULL | |
| state | varchar(191) | YES | | NULL | |
| country | varchar(191) | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
| user_id | int(11) | YES | | NULL | |
| address | varchar(191) | YES | | NULL | |
| address2 | varchar(191) | YES | | NULL | |
| zip | varchar(10) | YES | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
| parent_id | int(11) | YES | | NULL | |
| currency | varchar(10) | YES | | NULL | |
| ldap_ou | varchar(191) | YES | | NULL | |
| manager_id | int(11) | YES | | NULL | |
| image | varchar(191) | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
The CSV looks like
id name city state country created_at updated_at user_id address address2 zip deleted_at parent_id currency ldap_ou manager_id image
testname NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
id is blank
But the warning shows
MariaDB [snipeit]> show warnings;
+---------+------+------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: '' for column 'id' at row 1 |
| Warning | 1265 | Data truncated for column 'created_at' at row 1 |
| Warning | 1265 | Data truncated for column 'updated_at' at row 1 |
| Warning | 1366 | Incorrect integer value: 'NULL' for column 'user_id' at row 1 |
| Warning | 1265 | Data truncated for column 'deleted_at' at row 1 |
| Warning | 1366 | Incorrect integer value: 'NULL' for column 'parent_id' at row 1 |
| Warning | 1366 | Incorrect integer value: 'NULL' for column 'manager_id' at row 1
Any idea why this would be? I thought if a field has NULL I can use NULL on it?
The command I used to import is
load data local infile '/media/Share1/CSV_Files/test.csv' into TABLE locations fields terminated by ',' ignore 1 lines;
Cheers
There are lots of mistakes :
Then try to load your file again and tell us if there are other errors.
What you might want to do is :
And use the following command :
EDIT : Your command should specify columns that appears in your csv file like this (in the right order !!):
EDIT 2 :
from https://dev.mysql.com/doc/refman/8.0/en/problems-with-null.html
So your csv should look like :
EDIT 3 : It may be the final solution. Do not specify id field in the csv file as just above in EDIT 2. And use the following command :