Changeset 2346
- Timestamp:
- 02/18/06 15:26:28 (2 years ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/core/db/backends/ado_mssql.py (modified) (1 diff)
- django/trunk/django/core/db/backends/mysql.py (modified) (1 diff)
- django/trunk/django/core/db/backends/postgresql.py (modified) (1 diff)
- django/trunk/django/core/db/backends/sqlite3.py (modified) (1 diff)
- django/trunk/django/core/db/__init__.py (modified) (1 diff)
- django/trunk/django/core/management.py (modified) (3 diffs)
- django/trunk/docs/django-admin.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r2341 r2346 52 52 Jeremy Dunck <http://dunck.us/> 53 53 Clint Ecker 54 gandalf@owca.info 54 55 Baishampayan Ghose 55 56 Espen Grindhaug <http://grindhaug.org/> django/trunk/django/core/db/backends/ado_mssql.py
r2325 r2346 119 119 raise NotImplementedError 120 120 121 def get_indexes(cursor, table_name): 122 raise NotImplementedError 123 121 124 OPERATOR_MAPPING = { 122 125 'exact': '= %s', django/trunk/django/core/db/backends/mysql.py
r2325 r2346 135 135 def get_relations(cursor, table_name): 136 136 raise NotImplementedError 137 138 def get_indexes(cursor, table_name): 139 "Returns a dict of indexes for given table" 140 cursor.execute("SHOW INDEX FROM %s" % DatabaseWrapper().quote_name(table_name)) 141 indexes = {} 142 for row in cursor.fetchall(): 143 indexes[row[4]] = {'keyname': row[2], 'unique': not bool(row[1])} 144 return indexes 137 145 138 146 OPERATOR_MAPPING = { django/trunk/django/core/db/backends/postgresql.py
r2325 r2346 126 126 continue 127 127 return relations 128 129 def get_indexes(cursor, table_name): 130 raise NotImplementedError 128 131 129 132 # Register these custom typecasts, because Django expects dates/times to be django/trunk/django/core/db/backends/sqlite3.py
r2325 r2346 133 133 134 134 def get_relations(cursor, table_name): 135 raise NotImplementedError 136 137 def get_indexes(cursor, table_name): 135 138 raise NotImplementedError 136 139 django/trunk/django/core/db/__init__.py
r1484 r2346 38 38 get_table_description = dbmod.get_table_description 39 39 get_relations = dbmod.get_relations 40 get_indexes = dbmod.get_indexes 40 41 OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING 41 42 DATA_TYPES = dbmod.DATA_TYPES django/trunk/django/core/management.py
r2328 r2346 596 596 except NotImplementedError: 597 597 relations = {} 598 try: 599 indexes = db.get_indexes(cursor, table_name) 600 except NotImplementedError: 601 indexes = {} 598 602 for i, row in enumerate(db.get_table_description(cursor, table_name)): 599 column_name = row[0]603 att_name = row[0] 600 604 comment_notes = [] # Holds Field notes, to be displayed in a Python comment. 601 605 extra_params = {} # Holds Field parameters such as 'db_column'. 602 606 603 if keyword.iskeyword( column_name):604 extra_params['db_column'] = column_name605 column_name += '_field'607 if keyword.iskeyword(att_name): 608 extra_params['db_column'] = att_name 609 att_name += '_field' 606 610 comment_notes.append('Field renamed because it was a Python reserved word.') 607 611 … … 609 613 rel_to = relations[i][1] == table_name and "'self'" or table2model(relations[i][1]) 610 614 field_type = 'ForeignKey(%s' % rel_to 611 if column_name.endswith('_id'):612 column_name = column_name[:-3]615 if att_name.endswith('_id'): 616 att_name = att_name[:-3] 613 617 else: 614 extra_params['db_column'] = column_name618 extra_params['db_column'] = att_name 615 619 else: 616 620 try: … … 626 630 extra_params.update(new_params) 627 631 632 # Add maxlength for all CharFields. 628 633 if field_type == 'CharField' and row[3]: 629 634 extra_params['maxlength'] = row[3] 630 635 636 # Add primary_key and unique, if necessary. 637 column_name = extra_params.get('db_column', att_name) 638 if column_name in indexes: 639 if indexes[column_name]['keyname'] == 'PRIMARY': 640 extra_params['primary_key'] = True 641 elif indexes[column_name]['unique']: 642 extra_params['unique'] = True 643 631 644 field_type += '(' 632 645 633 field_desc = '%s = meta.%s' % (column_name, field_type) 646 # Don't output 'id = meta.AutoField(primary_key=True)', because 647 # that's assumed if it doesn't exist. 648 if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}: 649 continue 650 651 field_desc = '%s = meta.%s' % (att_name, field_type) 634 652 if extra_params: 635 653 if not field_desc.endswith('('): django/trunk/docs/django-admin.txt
r2271 r2346 113 113 This feature is meant as a shortcut, not as definitive model generation. After 114 114 you run it, you'll want to look over the generated models yourself to make 115 customizations. In particular, you'll need to do this: 116 117 * Rearrange models' order, so that models that refer to other models are 118 ordered properly. 119 * Add ``primary_key=True`` to one field in each model. The ``inspectdb`` 120 doesn't yet introspect primary keys. 115 customizations. In particular, you'll need to rearrange models' order, so that 116 models that refer to other models are ordered properly. 117 118 If you're using Django 0.90 or 0.91, you'll need to add ``primary_key=True`` to 119 one field in each model. In the Django development version, primary keys are 120 automatically introspected for MySQL, and Django puts in the 121 ``primary_key=True`` where needed. 121 122 122 123 ``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection
