Django

Code

Changeset 2711

Show
Ignore:
Timestamp:
04/17/06 16:02:32 (3 years ago)
Author:
adrian
Message:

magic-removal: Fixed #1544 -- Changed 'inspectdb' to use database name from DATABASE_NAME setting instead of command line. Thanks, pb

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/core/management.py

    r2709 r2711  
    669669startapp.args = "[appname]" 
    670670 
    671 def inspectdb(db_name): 
     671def inspectdb(): 
    672672    "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." 
    673673    from django.db import connection, get_introspection_module 
     
    681681        return object_name.endswith('s') and object_name[:-1] or object_name 
    682682 
    683     settings.DATABASE_NAME = db_name 
    684683    cursor = connection.cursor() 
    685684    yield "# This is an auto-generated Django model module." 
     
    777776        yield '' 
    778777inspectdb.help_doc = "Introspects the database tables in the given database and outputs a Django model module." 
    779 inspectdb.args = "[dbname]
     778inspectdb.args = "
    780779 
    781780class ModelErrorCollection: 
     
    11541153    elif action == 'inspectdb': 
    11551154        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](): 
    11611156                print line 
    11621157        except NotImplementedError: 
  • django/branches/magic-removal/docs/django-admin.txt

    r2693 r2711  
    9292Note that Django's default settings live in ``django/conf/global_settings.py``. 
    9393 
    94 inspectdb [dbname] 
    95 ------------------ 
    96  
    97 Introspects the database tables in the given database and outputs a Django 
    98 model module to standard output. 
     94inspectdb 
     95--------- 
     96 
     97Introspects the database tables in the database pointed-to by the 
     98``DATABASE_NAME`` setting and outputs a Django model module to standard output. 
    9999 
    100100Use this if you have a legacy database with which you'd like to use Django. 
     
    125125models that refer to other models are ordered properly. 
    126126 
    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. 
     127Primary keys are automatically introspected for PostgreSQL and MySQL, and 
     128Django puts in the ``primary_key=True`` where needed. 
    131129 
    132130``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection 
    133 only works in PostgreSQL
     131only works in PostgreSQL and with certain types of MySQL tables
    134132 
    135133install [modelmodule modelmodule ...] 
  • django/branches/magic-removal/docs/legacy_databases.txt

    r2608 r2711  
    1919`settings file`_: 
    2020 
     21    * `DATABASE_NAME` 
    2122    * `DATABASE_ENGINE`_ 
    2223    * `DATABASE_USER`_ 
     
    2728 
    2829.. _settings file: http://www.djangoproject.com/documentation/settings/ 
     30.. _DATABASE_NAME: http://www.djangoproject.com/documentation/settings/#database-name 
    2931.. _DATABASE_ENGINE: http://www.djangoproject.com/documentation/settings/#database-engine 
    3032.. _DATABASE_USER: http://www.djangoproject.com/documentation/settings/#database-user 
     
    4042database. You can view the output by running this command:: 
    4143 
    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 
    4545 
    4646Save this as a file by using standard Unix output redirection:: 
    4747 
    48     django-admin.py inspectdb [databasename] --settings=path.to.settings > appname.py 
     48    django-admin.py inspectdb --settings=path.to.settings > appname.py 
    4949 
    5050This feature is meant as a shortcut, not as definitive model generation. See