legacy_databases.txt 2.2 KB

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