Django and Databases: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
Line 13: Line 13:
=== Editing models in a reusable package/app ===
=== Editing models in a reusable package/app ===


* Edit `models.py` in the package.  
Edit `models.py` in the package.  
* Repackage the app.<ref>[https://docs.djangoproject.com/en/1.8/intro/reusable-apps/ How to Write Reusable Apps] - Django Documentation</ref>
 
** `python setup.py sdist` (from within the root package directory)
Repackage the app (from within the root package directory).<ref>[https://docs.djangoproject.com/en/1.8/intro/reusable-apps/ How to Write Reusable Apps] - Django Documentation</ref>
* Update the package/app, e.g:
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ pip uninstall django-addresses
$ python setup.py sdist
$ pip install ~/develop/labs/shared/django-addresses/dist/django-addresses-1.2.1.tar.gz
</syntaxhighlight>
 
Update the package/app (See also [[Reusable Django Packages/Apps]]), e.g:
 
<syntaxhighlight lang="bash">
$ pip uninstall django-contact_info
$ pip install ~/develop/labs/shared/django-addresses/dist/django-contact_info-1.2.1.tar.gz
</syntaxhighlight>
 
Make migrations in the Django project.
 
<syntaxhighlight lang="bash">
$ cd /path/to/django/project/
$ python manage.py makemigrations contact_info
$ python manage.py migrate
</syntaxhighlight>
</syntaxhighlight>
:* (See also [[Reusable Django Packages/Apps]])


== Notes ==
== Notes ==
<references />
<references />

Revision as of 18:16, 1 September 2015

Updating database structure

Workflow [1]

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 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

Notes

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