1 ==================================
2 Integrating with a legacy database
3 ==================================
5 While Django is best suited for developing new applications, it's quite
6 possible to integrate it into legacy databases. Django includes a couple of
7 utilities to automate as much of this process as possible.
9 This document assumes you know the Django basics, as covered in the
12 .. _official tutorial: ../tutorial01/
14 Give Django your database parameters
15 ====================================
17 You'll need to tell Django what your database connection parameters are, and
18 what the name of the database is. Do that by editing these settings in your
24 * `DATABASE_PASSWORD`_
28 .. _settings file: ../settings/
29 .. _DATABASE_NAME: ../settings/#database-name
30 .. _DATABASE_ENGINE: ../settings/#database-engine
31 .. _DATABASE_USER: ../settings/#database-user
32 .. _DATABASE_PASSWORD: ../settings/#database-password
33 .. _DATABASE_HOST: ../settings/#database-host
34 .. _DATABASE_PORT: ../settings/#database-port
36 Auto-generate the models
37 ========================
39 Django comes with a utility that can create models by introspecting an existing
40 database. You can view the output by running this command::
42 python manage.py inspectdb
44 Save this as a file by using standard Unix output redirection::
46 python manage.py inspectdb > models.py
48 This feature is meant as a shortcut, not as definitive model generation. See
49 the `django-admin.py documentation`_ for more information.
51 Once you've cleaned up your models, name the file ``models.py`` and put it in
52 the Python package that holds your app. Then add the app to your
53 ``INSTALLED_APPS`` setting.
55 .. _django-admin.py documentation: ../django-admin/
57 Install the core Django tables
58 ==============================
60 Next, run the ``manage.py syncdb`` command to install any extra needed database
61 records such as admin permissions and content types::
63 python manage.py syncdb
68 That's it. Try accessing your data via the Django database API, and try editing
69 objects via Django's admin site.