0
votes

I'm migrating my Django database from sqlite to mysql. I've done the following with no problems:

python manage.py dumpdata > datadump.json Change your settings.py to the mysql database.

But when I issue the following command python manage.py loaddata datadump.json I get this error:

IntegrityError: (1062, "Duplicate entry '13-13' for key 'from_category_id'")

Can someone tell me how to go about fixing this issue so that I can run the command again and hopefully load my data?

Thanks, J.

1
1. Do you have existing data in the DB?ismail
yes, I have data in the database.jimmyc3po

1 Answers

1
votes
  1. Do you have existing data in theDB?,
  2. try with indent --4 to get a version that you can eyeball
  3. Post some sample data
  4. It looks like you got a duplicate key violation or your data you are trying to insert does not match the column type i.e check the constraints applied in your models.py, field types, and the tables created in mysql

The question then will be why does it work in SQLITE and not my sql?

Simple really, SQLITE does not do any type checking, i.e you could easily insert text into an integer field. You will need to clean your data before inserting it into MySQL.

Unlike most SQL databases, SQLite does not restrict the type of data that may be inserted into a column based on the columns declared type. Instead, SQLite uses dynamic typing.

From http://www.sqlite.org/lang_createtable.html