Django and Databases

From Littledamien Wiki
Jump to navigation Jump to search

Updating database structure[edit]

Workflow [1][edit]

After changing the structure of a model in the Django code,

$ python manage.py makemigrations
$ python manage.py migrate

Editing models in a reusable package/app[edit]

Edit models.py in the package.

Repackage the app (from within the root package directory).[2]

$ python setup.py sdist

Update the package/app (See also Reusable Django Packages/Apps), e.g:

$ pip uninstall django-contact_info
$ pip install ~/develop/labs/shared/django-addresses/dist/django-contact_info-1.2.1.tar.gz

Make migrations in the Django project.

$ cd /path/to/django/project/
$ python manage.py makemigrations contact_info
$ python manage.py migrate contact_info

Notes[edit]

  1. Migrations - Django Documentation (v1.8)
  2. How to Write Reusable Apps - Django Documentation