89
Execute:
python manage.py dumpdata > datadump.json
Next, change your settings.py to the mysql database.
Finally:
python manage.py loaddata datadump.json
74
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
- Change settings.py to your mysql
- Make sure you can connect on your mysql (permissions,etc)
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!
- [Django]-Can I have a Django form without Model
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
11
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
- [Django]-Generics vs viewset in django rest framework, how to prefer which one to use?
- [Django]-Django filter the model on ManyToMany count?
- [Django]-How to write a unit test for a django view?
2
A (fuller) list of the steps I needed for moving from sqlite to MySQL, YMMV:
- python manage.py dumpdata > datadump.json
- Make sure you can connect on your mysql (permissions, etc)
- Make sure you HAVE PRIVILEGES to modify FOREIGN_KEY_CHECKS (I had to install and run my own private instance of mysql for that)
- Make sure InnoDB engine is NOT used (use MyISAM in every table) or the next step won’t work (failing silently)!
- Relax validation by this command (this won’t take effect in InnoDB):
SET GLOBAL FOREIGN_KEY_CHECKS = 0;
- Load django_site.sql table separately (if using contrib.sites)
- Change settings.py to your new mysql
- python manage.py migrate –run-syncdb
- Fix syncdb errors errors by tinkering with the code in /migrations directories of your Django apps and the DB tables as necessary
- Exclude contentype data with this snippet (can put it in the main urls.py module):
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
- If need editing json data have to prettify it first:
cat datadump.json | python -m json.tool > datadump_pretty.json
- python manage.py loaddata datadump.json
- Fix any data truncation issues
- Add timezone data to the database:
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
- Test the site is working without submitting any data
- SET GLOBAL FOREIGN_KEY_CHECKS = 1;
- Test the rest
- [Django]-How do I check for last loop iteration in Django template?
- [Django]-Django multiple template inheritance – is this the right style?
- [Django]-How do I package a python application to make it pip-installable?
Source:stackexchange.com