Changeset 2711
- Timestamp:
- 04/17/06 16:02:32 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/core/management.py
r2709 r2711 669 669 startapp.args = "[appname]" 670 670 671 def inspectdb( db_name):671 def inspectdb(): 672 672 "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." 673 673 from django.db import connection, get_introspection_module … … 681 681 return object_name.endswith('s') and object_name[:-1] or object_name 682 682 683 settings.DATABASE_NAME = db_name684 683 cursor = connection.cursor() 685 684 yield "# This is an auto-generated Django model module." … … 777 776 yield '' 778 777 inspectdb.help_doc = "Introspects the database tables in the given database and outputs a Django model module." 779 inspectdb.args = " [dbname]"778 inspectdb.args = "" 780 779 781 780 class ModelErrorCollection: … … 1154 1153 elif action == 'inspectdb': 1155 1154 try: 1156 param = args[1] 1157 except IndexError: 1158 parser.print_usage_and_exit() 1159 try: 1160 for line in action_mapping[action](param): 1155 for line in action_mapping[action](): 1161 1156 print line 1162 1157 except NotImplementedError: django/branches/magic-removal/docs/django-admin.txt
r2693 r2711 92 92 Note that Django's default settings live in ``django/conf/global_settings.py``. 93 93 94 inspectdb [dbname]95 --------- ---------96 97 Introspects the database tables in the given database and outputs a Django98 model module to standard output.94 inspectdb 95 --------- 96 97 Introspects the database tables in the database pointed-to by the 98 ``DATABASE_NAME`` setting and outputs a Django model module to standard output. 99 99 100 100 Use this if you have a legacy database with which you'd like to use Django. … … 125 125 models that refer to other models are ordered properly. 126 126 127 If you're using Django 0.90 or 0.91, you'll need to add ``primary_key=True`` to 128 one field in each model. In the Django development version, primary keys are 129 automatically introspected for PostgreSQL and MySQL, and Django puts in the 130 ``primary_key=True`` where needed. 127 Primary keys are automatically introspected for PostgreSQL and MySQL, and 128 Django puts in the ``primary_key=True`` where needed. 131 129 132 130 ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection 133 only works in PostgreSQL .131 only works in PostgreSQL and with certain types of MySQL tables. 134 132 135 133 install [modelmodule modelmodule ...] django/branches/magic-removal/docs/legacy_databases.txt
r2608 r2711 19 19 `settings file`_: 20 20 21 * `DATABASE_NAME` 21 22 * `DATABASE_ENGINE`_ 22 23 * `DATABASE_USER`_ … … 27 28 28 29 .. _settings file: http://www.djangoproject.com/documentation/settings/ 30 .. _DATABASE_NAME: http://www.djangoproject.com/documentation/settings/#database-name 29 31 .. _DATABASE_ENGINE: http://www.djangoproject.com/documentation/settings/#database-engine 30 32 .. _DATABASE_USER: http://www.djangoproject.com/documentation/settings/#database-user … … 40 42 database. You can view the output by running this command:: 41 43 42 django-admin.py inspectdb [databasename] --settings=path.to.settings 43 44 ...where "[databasename]" is the name of your database. 44 django-admin.py inspectdb --settings=path.to.settings 45 45 46 46 Save this as a file by using standard Unix output redirection:: 47 47 48 django-admin.py inspectdb [databasename]--settings=path.to.settings > appname.py48 django-admin.py inspectdb --settings=path.to.settings > appname.py 49 49 50 50 This feature is meant as a shortcut, not as definitive model generation. See
