diff --git a/django/core/management.py b/django/core/management.py index 31b61e2536..c85bbcbfe4 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -668,7 +668,7 @@ def startapp(app_name, directory): startapp.help_doc = "Creates a Django app directory structure for the given app name in the current directory." startapp.args = "[appname]" -def inspectdb(db_name): +def inspectdb(): "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." from django.db import connection, get_introspection_module from django.conf import settings @@ -680,7 +680,6 @@ def inspectdb(db_name): object_name = table_name.title().replace('_', '') return object_name.endswith('s') and object_name[:-1] or object_name - settings.DATABASE_NAME = db_name cursor = connection.cursor() yield "# This is an auto-generated Django model module." yield "# You'll have to do the following manually to clean this up:" @@ -776,7 +775,7 @@ def inspectdb(db_name): yield ' db_table = %r' % table_name yield '' inspectdb.help_doc = "Introspects the database tables in the given database and outputs a Django model module." -inspectdb.args = "[dbname]" +inspectdb.args = "" class ModelErrorCollection: def __init__(self, outfile=sys.stdout): @@ -1153,11 +1152,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING): action_mapping[action]() elif action == 'inspectdb': try: - param = args[1] - except IndexError: - parser.print_usage_and_exit() - try: - for line in action_mapping[action](param): + for line in action_mapping[action](): print line except NotImplementedError: sys.stderr.write(style.ERROR("Error: %r isn't supported for the currently selected database backend.\n" % action)) diff --git a/docs/django-admin.txt b/docs/django-admin.txt index fa493c4d0a..f77aebd330 100644 --- a/docs/django-admin.txt +++ b/docs/django-admin.txt @@ -91,11 +91,11 @@ example, the default settings don't define ``ROOT_URLCONF``, so Note that Django's default settings live in ``django/conf/global_settings.py``. -inspectdb [dbname] ------------------- +inspectdb +--------- -Introspects the database tables in the given database and outputs a Django -model module to standard output. +Introspects the database tables in the database pointed-to by the +``DATABASE_NAME`` setting and outputs a Django model module to standard output. Use this if you have a legacy database with which you'd like to use Django. The script will inspect the database and create a model for each table within @@ -124,13 +124,11 @@ you run it, you'll want to look over the generated models yourself to make customizations. In particular, you'll need to rearrange models' order, so that models that refer to other models are ordered properly. -If you're using Django 0.90 or 0.91, you'll need to add ``primary_key=True`` to -one field in each model. In the Django development version, primary keys are -automatically introspected for PostgreSQL and MySQL, and Django puts in the -``primary_key=True`` where needed. +Primary keys are automatically introspected for PostgreSQL and MySQL, and +Django puts in the ``primary_key=True`` where needed. ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection -only works in PostgreSQL. +only works in PostgreSQL and with certain types of MySQL tables. install [modelmodule modelmodule ...] ------------------------------------- diff --git a/docs/legacy_databases.txt b/docs/legacy_databases.txt index 992006b193..7ceefeb497 100644 --- a/docs/legacy_databases.txt +++ b/docs/legacy_databases.txt @@ -18,6 +18,7 @@ You'll need to tell Django what your database connection parameters are, and what the name of the database is. Do that by editing these settings in your `settings file`_: + * `DATABASE_NAME` * `DATABASE_ENGINE`_ * `DATABASE_USER`_ * `DATABASE_PASSWORD`_ @@ -26,6 +27,7 @@ what the name of the database is. Do that by editing these settings in your * `DATABASE_PORT`_ .. _settings file: http://www.djangoproject.com/documentation/settings/ +.. _DATABASE_NAME: http://www.djangoproject.com/documentation/settings/#database-name .. _DATABASE_ENGINE: http://www.djangoproject.com/documentation/settings/#database-engine .. _DATABASE_USER: http://www.djangoproject.com/documentation/settings/#database-user .. _DATABASE_PASSWORD: http://www.djangoproject.com/documentation/settings/#database-password @@ -39,13 +41,11 @@ Auto-generate the models Django comes with a utility that can create models by introspecting an existing database. You can view the output by running this command:: - django-admin.py inspectdb [databasename] --settings=path.to.settings - -...where "[databasename]" is the name of your database. + django-admin.py inspectdb --settings=path.to.settings Save this as a file by using standard Unix output redirection:: - django-admin.py inspectdb [databasename] --settings=path.to.settings > appname.py + django-admin.py inspectdb --settings=path.to.settings > appname.py This feature is meant as a shortcut, not as definitive model generation. See the `django-admin.py documentation`_ for more information.