#1328: Inspectdb generates bad python code if column name is python reserved 
word
------------------------------------------------+---------------------------
          Reporter:  [email protected]             |         Owner:  adrian
            Status:  closed                     |     Milestone:        
         Component:  django-admin.py inspectdb  |       Version:  1.2   
        Resolution:  fixed                      |      Keywords:        
             Stage:  Unreviewed                 |     Has_patch:  0     
        Needs_docs:  1                          |   Needs_tests:  0     
Needs_better_patch:  0                          |  
------------------------------------------------+---------------------------
Changes (by kmtracey):

  * status:  reopened => closed
  * resolution:  => fixed

Comment:

 (After 4 years it would be better to open a new ticket rather than re-
 opening one that is so old. This problem was assuredly fixed so whatever
 behavior you are seeing is due to something new that should get tracked on
 its own.)

 I cannot recreate what you describe. With the current 1.2.X branch code,
 given a MySQL table:

 {{{
 mysql> describe testme;
 +-------+--------------+------+-----+---------+----------------+
 | Field | Type         | Null | Key | Default | Extra          |
 +-------+--------------+------+-----+---------+----------------+
 | id    | int(11)      | NO   | PRI | NULL    | auto_increment |
 | from  | varchar(512) | YES  |     | NULL    |                |
 +-------+--------------+------+-----+---------+----------------+
 2 rows in set (0.00 sec)
 }}}

 with a column named from, inspectdb produces:

 {{{
 #!python
 # This is an auto-generated Django model module.
 # You'll have to do the following manually to clean this up:
 #     * Rearrange models' order
 #     * Make sure each model has one field with primary_key=True
 # Feel free to rename the models, but don't rename db_table values or
 field names.
 #
 # Also note: You'll have to insert the output of 'django-admin.py
 sqlcustom [appname]'
 # into your database.

 from django.db import models

 class Testme(models.Model):
     id = models.IntegerField(primary_key=True)
     from_field = models.CharField(max_length=1536, db_column='from',
 blank=True) # Field renamed because it was a Python reserved word. Field
 name made lowercase.
     class Meta:
         db_table = u'testme'

 }}}

 So if you do open a new ticket please provide more details (database,
 description of the table as per whatever db utility that database
 supports, exact output from inspectdb) that would help someone figure out
 what is going on. It is apparently not enough to simply have a column
 named 'from' in a table.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/1328#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to