Django

Code

root/django/tags/releases/0.95/docs/legacy_databases.txt

Revision 2809, 2.7 kB (checked in by adrian, 3 years ago)

MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.

Line 
1 ==================================
2 Integrating with a legacy database
3 ==================================
4
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.
8
9 This document assumes you know the Django basics, as covered in the
10 `official tutorial`_.
11
12 .. _official tutorial: http://www.djangoproject.com/documentation/tutorial1/
13
14 Give Django your database parameters
15 ====================================
16
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
19 `settings file`_:
20
21     * `DATABASE_NAME`
22     * `DATABASE_ENGINE`_
23     * `DATABASE_USER`_
24     * `DATABASE_PASSWORD`_
25     * `DATABASE_NAME`_
26     * `DATABASE_HOST`_
27     * `DATABASE_PORT`_
28
29 .. _settings file: http://www.djangoproject.com/documentation/settings/
30 .. _DATABASE_NAME: http://www.djangoproject.com/documentation/settings/#database-name
31 .. _DATABASE_ENGINE: http://www.djangoproject.com/documentation/settings/#database-engine
32 .. _DATABASE_USER: http://www.djangoproject.com/documentation/settings/#database-user
33 .. _DATABASE_PASSWORD: http://www.djangoproject.com/documentation/settings/#database-password
34 .. _DATABASE_NAME: http://www.djangoproject.com/documentation/settings/#database-name
35 .. _DATABASE_HOST: http://www.djangoproject.com/documentation/settings/#database-host
36 .. _DATABASE_PORT: http://www.djangoproject.com/documentation/settings/#database-port
37
38 Auto-generate the models
39 ========================
40
41 Django comes with a utility that can create models by introspecting an existing
42 database. You can view the output by running this command::
43
44     django-admin.py inspectdb --settings=path.to.settings
45
46 Save this as a file by using standard Unix output redirection::
47
48     django-admin.py inspectdb --settings=path.to.settings > models.py
49
50 This feature is meant as a shortcut, not as definitive model generation. See
51 the `django-admin.py documentation`_ for more information.
52
53 Once you've cleaned up your models, name the file ``models.py`` and put it in
54 the Python package that holds your app. Then add the app to your
55 ``INSTALLED_APPS`` setting.
56
57 .. _django-admin.py documentation: http://www.djangoproject.com/documentation/django_admin/
58
59 Install the core Django tables
60 ==============================
61
62 Next, run the ``manage.py syncdb`` command to install any extra needed database
63 records such as admin permissions and content types::
64
65     django-admin.py init --settings=path.to.settings
66
67 See whether it worked
68 =====================
69
70 That's it. Try accessing your data via the Django database API, and try editing
71 objects via Django's admin site.
Note: See TracBrowser for help on using the browser.