I'm working on a legacy mysql db (under Mac OS X with Django 1.4.3) whose structure I cannot modify because other applications are already happily referring to it (FileMaker pro, PHP,etc.).
After issuing the 'python manage.py inspectdb' I created the first tentative models.py that I'm now refining specifically to take into account foreign keys.
Now, manage.py both syncdb and runserver don't signal anything abnormal but when I browse the table articoli as admin the following two tables and classes are arising a problem because
(1054, "Unknown column 'articoli.categoria_id_id' in 'field list'")
<SNIP models.py>
................
...............
class Categorie(models.Model):
idCategoria = models.IntegerField(primary_key=True)
descrizione = models.CharField(max_length=150, db_column='Descrizione') # Field name made lowercase.
def __unicode__(self):
return self.descrizione
class Meta:
db_table = u'Categorie'
verbose_name_plural='categorie'
ordering=['descrizione']
class Articoli(models.Model):
id = models.IntegerField(primary_key=True)
categoria_id = models.ForeignKey(Categorie)
codice = models.CharField(max_length=90, unique=True, db_column='Codice')
...............................
...............................
</SNIP>
How can I specify in categoria_id of class Articoli that the key field to refer to is idCategoria of Categorie?
Ciao
Vittorio
In exactly the same way you've done elsewhere, by using `db_column`.
I would definitely recommend calling the model field `categoria` without the `_id` though, as it is not an id, it's a reference to the entire related model instance.
--
DR.
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment