Django Import/Export in a table where foreign key is a string - constantly throws an error Column 'system': invalid literal for int() with base 10

772 views python
-3

I have explored a lot of examples django export/import. When I try importing in a table with foreign key with datatype string, I get this error - " invalid literal for int() with base 10", which I understand because the foreign key field has datatype 'int'.

But for that before importing, do I have to edit the column in my csv with 'int' id values of the column being looked up for translating the foreign key value.Please share any working examples, I want to use a column of datatype string as foreign key and not the integer.

answered question

kindly consider adding more information , e.g. the part of the code that is creating issues

1 Answer

8

Without an example it would be difficult to tell the exact issue. But from what you have posted. I guess the problem you are facing is you have the id value as floating number.

int('55063.000000')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '55063.000000'

To solve it you can do something like this

int(float('55063.000000'))  
55063

posted this

Have an answer?

JD

Please login first before posting an answer.