I need to migrate my db from sqlite to mysql, and the various tools/scripts out there are too many for me to easily spot the safest and most elegant solution.
This s
A (fuller) list of the steps I needed for moving from sqlite to MySQL, YMMV:
SET GLOBAL FOREIGN_KEY_CHECKS = 0;
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
cat datadump.json | python -m json.tool > datadump_pretty.json
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -D mysql -P 1234 -u root -p --protocol=tcp
mysql -P 1234 -u root -p -e "flush tables" --protocol=tcp
This is a neater way to avoid the ContentType
issues described elsewhere:
./manage.py dumpdata --exclude contenttypes --exclude auth.permission --exclude sessions --indent 2 > dump.json
Then:
./manage.py loaddata dump.json
Execute:
python manage.py dumpdata > datadump.json
Next, change your settings.py to the mysql database.
Finally:
python manage.py loaddata datadump.json
After some hard searching I got several problems that I hope future answer looking people will find useful.
my formula is
python manage.py dumpdata > datadump.json
python manage.py migrate --run-syncdb
Exclude contentype data with this snippet in shell
python manage.py shell
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
python manage.py loaddata datadump.json
Hope that will help you!