Hi all,
I'm working with a MySQL legacy DB which was changed.

This was our previous Level table:
+-----------------+---------------+------+-----+---------+-------+
| Field           | Type          | Null | Key | Default | Extra |
+-----------------+---------------+------+-----+---------+-------+
| level_name      | varchar(20)   | NO   | PRI |         |       |
| instrument_name | varchar(20)   | NO   | PRI |         |       |
| available       | enum('Y','N') | NO   |     | Y       |       |
| tablename       | varchar(20)   | YES  |     | NULL    |       |
+-----------------+---------------+------+-----+---------+-------+

This was the previous model class for the Level table:

class Level(models.Model):
    level_name = models.CharField(primary_key=True, maxlength=60)
    instrument_name = models.CharField(blank=False, maxlength=60)
    available = models.TextField(blank=False)
    tablename = models.CharField(blank=True, maxlength=60)

Because in the database the primary key was made of two fields, the
level_name and the instrument_name this wasn't working properly. So we
changed the table to:

+-----------------+---------------+------+-----+---------
+----------------+
| Field           | Type          | Null | Key | Default |
Extra          |
+-----------------+---------------+------+-----+---------
+----------------+
| level_name      | varchar(20)   | NO   | MUL |
|                |
| instrument_name | varchar(20)   | NO   |     |
|                |
| available       | enum('Y','N') | NO   |     | Y
|                |
| tablename       | varchar(20)   | YES  |     | NULL
|                |
| levelID         | bigint(20)    | NO   | PRI | NULL    |
auto_increment |
+-----------------+---------------+------+-----+---------
+----------------+

and the Level model class to (with the help of the inspectdb command):

class Level(models.Model):
    level_name = models.CharField(unique=True, maxlength=60)
    instrument_name = models.CharField(unique=True, maxlength=60)
    available = models.TextField()
    tablename = models.CharField(blank=True, maxlength=60)
    levelID_id = models.AutoField(primary_key=True)

But now, when I try to do for example this:

def view_levels(request, orderby):

    levels=Level.objects.all()

    levellist=[]
    for l in levels:
        levellist.append({'levelname':l.level_name,
                      'instrname':l.instrument_name,
                      'available':l.available,
                      'tablename':l.tablename})

    ordering='Instrument Name'
    return render_to_response('view_levels.html',
{'levellist':levellist, 'ordering':ordering})

It gives me this error:

Exception Type:         OperationalError
Exception Value:        (1054, "Unknown column 'Level.levelID_id' in 'field
list'")
Exception Location:     /nobackup/reis/Python/lib/python2.5/site-packages/
MySQLdb/connections.py in defaulterrorhandler, line 35

What is happening here?
Thanks for your time!

Ana


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

Reply via email to