Make fixtures for the standard Django's apps - django

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.

Related

no such table: Append_employeemodel Django

GitHub repository
When I send a post request I get this.
I previously try
python manage.py syncdb
./manage.py migrate
python manage.py migrate
python manage.py createsuperuser
python manage.py makemigrations
python manage.py migrate
but I still got an error. The Git Hub link is above please help me.
Django looks for models in a models.py file or models directory, not 'model.py'.
I'd strongly suggest you use django-admin startproject name [directory] when creating new projects or django-admin startapp name [directory] when creating new apps in order for a consistent directory structure to be generated.
Also try and follow the naming conventions in Django. For example employeeModel could rather be Employee, empName rather employee_name, TradeInfo rather trade_info, etc.

Convert Full Database to Different database Format using 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.

Django makemigrations app order

I'm using Django 1.8.4. As my project is still under construction, I frequently remove all migration scripts, and rerun makemigrations to generate the initial migration scripts.
I found makemigrations would generate two migration scripts for one of my apps while other apps just have 0001_initial.py. It would be something like:
- 0001_initial.py
- 0002_auto_20150919_1645.py
I checked the content of 0002_auto_20150919_1645.py, it was adding foreign field from the other app's model.
I guess it might be related to the order of creating migrations for apps. So I delete these two migration scripts of this app and then run makemigrations again. Now I have only one migration script for this app.
My questions is:
Is there any way I can control the order makemigrations create migrations for apps?
For example, I have two apps, app1 and app2, and app1 depends on app2. Is it possible makemigrations create migration for app2 first, and then app1?
You can manually run migrations for an individual app.
./manage.py makemigrations app2
./manage.py makemigrations app1
./manage.py makemigrations # migrate the rest of your apps
You could also squash your existing migrations.

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

Running manage.py dumpdata on apps with dots in their names

I'm trying to do moving some data from my development machine to a server using dumpdata but ran into a problem.
So, say I want to dump the data that belongs to the app django.contrib.auth.
django.contrib.auth is in my INSTALLED_APPS.
This happens when I run
$ python manage.py dumpdata django.contrib.auth
Error: Unknown application: django.contrib.auth
The strange thing is that I can do manage.py testserver (i.e. nothing is broken) or do
$ python
>>> import django.contrib.auth
So there is nothing wrong with the python path.
I can run dumpdata on apps that are located straight in my project's dir.
If I leave out the apps' names, django.contrib.auth's tables are dumped as expected.
So, why can't I point out a specific app with dots in the name? I have tried to dump
other apps that are located in site-packages with the same result.
Try instead:
python manage.py dumpdata auth
The dumpdata command doesn't require the (fully qualified) package name of the app, only the name.