You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Greetings, I used inspectdb to create my models and then tried editing
the generated models in order to define the ForeignKey relationships,
and I'm getting an error.
Here's what I have. Note: I commented out the original category field
and tried adding my own ForeignKey
class MdlCourseCategories(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=765)
description = models.TextField(blank=True)
parent = models.IntegerField()
Using these models I do the following in the manage.py shell
>>> from cca.moodle.models import *
>>> cs = MdlCourse.objects.all()
>>> cs
OperationalError: (1054, "Unknown column 'mdl_course.category_id' in
'field list'")
to_field doesn't work quite like I expected. Does anyone know a way to
make models.ForeignKey to at a specific table.column?
Humblest Thanks and Kind Regards
--
matthew
carole...@gmail.com
unread,
Apr 3, 2008, 12:05:16 AM4/3/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
In your database ( not in the model ) rename the field 'category in
table MdlCourse to category_id and it should fix the problem...
normally a ForeignKey field name in the database is ClassName_id
Karen Tracey
unread,
Apr 3, 2008, 12:29:49 AM4/3/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
In your database ( not in the model ) rename the field 'category in
table MdlCourse to category_id and it should fix the problem...
normally a ForeignKey field name in the database is ClassName_id
Or, if you do not want to change your database column name, you can tell Django what it is by passing db_column='category' as an argument on the ForeignKey definition for category. Note the to_field argument is not needed here, by default the to_field is assumed to be the target model's primary key, and that is what you are using.
Karen
mthorley
unread,
Apr 3, 2008, 10:39:36 AM4/3/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Thanks so much Karen, that is exactly what I needed!