Convert Full Database to Different database Format using django - django

I'm switching my database engine and need to convert my data. I can access both databases in a python shell with .using('[database]'). Does django have any built-in backup&restore functions that I could use to fill my empty(but migrated) new database?

You can use dumpdata to export and loaddata to import.
Here are some examples:
dumpdata everything
python manage.py dumpdata > all.json
dumpdata one app
python manage.py dumpdata blog > blog.json
dumpdata specific model of app
python manage.py dumpdata blog.articles > blog_articles.json
loaddata
python manage.py loaddata all.json
By changing the settings.py database connection after you've dumped your data you don't have to use using at all.
More on this in the Django Docs.

Related

Make fixtures for the standard Django's apps

I need to make the fixtures for the redirect app. For site I use:
python3 manage.py dumpdata sites --indent 2 > fixtures/sites.json
So I tried to use the code below to make the fixtures for redirect:
python3 manage.py dumpdata redirect --indent 2 > fixtures/redirect.json
But I see the error below:
CommandError: No installed app with label 'redirect'.
I need to make the fixtures for all standard app, like migrations and the others in the image below.

No table created in db.sqlite3 after migrate and makemigrates in Django

I did this command and after that, only the DB file was created without any tables.
python manage.py makemigrations
python manage.py migrate
also I use the app name in this commands but nothing changed.
After that, I saw this DB file:

Django Migrations command workflow

There are three migration commands in Django:
python manage.py makemigrations
python manage.py migrate
python manage.py syncdb
In what order do these commands should be executed in terms of workflow of a basic project?
I am using Version: 1.8
syncdb is deprecated and does the same as migrate.
Whenever you make a change to your models, and when you first create them, each time you'd want to first run makemigrations to create the migration files, then migrate to apply them to your database.

django-sitetree how to migrate data to production server

I'm using south to migrate schemes to production. Also I'm using the django-sitetree module to show the menu in my site.
There is no problem with schema migration by using commands:
./manage.py schemamigration myApp --freeze sitetree --auto
./manage.py migrate myApp
However when I'm trying to migrate the sitetree data by command:
./manage.py datamigration myApp "new_version" --freeze sitetree
it doesn't generate any of created sitetree elements.
Ok, after some research and thanks to this sources: Altering database tables in Django and Fixtures and initial data blog, it seems that the better way to pass the menu data by using initial_data.json file with fixtures.
Create "fixtures" folder inside your App folder.
Run ./manage.py dumpdata --format=json --indent=4 sitetree > APP_PATH/fixtures/initial_data.json You can add more app to the command if you wish their data to be migrated to other environments.
The saved data to fixtures/initial_data.json will be always inserted/replaced by running ./manage.py syncdb Remember that the data will be replaced if it already exists in DB, it means that you should not dump the dynamic data.
There is the other way to migrate the sitetree using sitetree management command
# Dump...
python manage.py sitetreedump > treedump.json
# Restore...
python manage.py sitetreeload --mode=replace treedump.json
Thank you to idle-sign for this link

Google App Engine: Django Load Fixtures

Normally we load fixtures, like:
python manage.py loaddata fixture.yaml
but to upload to google database, it was suggested on here previously:
python manage.py loaddata remote fixture.yaml , but when I try, it says Unknown command: 'remote'
I use Djangoo 1.4, and I have - remote_api: on in my app.yaml, under built-ins.
You are almost there. Instead of using
python manage.py loaddata remote fixture.yaml
you should type
python manage.py remote loaddata fixture.yaml