Skip to content
Advertisement

Django csv upload to db works but throws error

I have created an app named customer within a project named Website using django. I have created a csv upload in the admin area which is connected to the Postgres db.

JavaScript

However the CSV file is still added to the db but the error screen is displayed. Even more strangely if I a notepad doc as csv containing the data and upload that I get no error until I try to upload a second data set. If I save an excel doc as csv I get the error. Where am I going wrong ?

JavaScript

Advertisement

Answer

Due to the nature of csv, you need to check if the length of your field item is 2.

i.e.

JavaScript

This way, you skip processing lines which are empty. Note that I’m assuming your expected field lengths is 2.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement