Search code examples
djangoinspectdb

Django - Inspectdb support this kind of database tables?


I have tested to "inspectdb" but I think my schema is to complex, for example... for the table "tdir_files_context" (djangoinspectdb.JPG "image in attachment") I got this model:

class TdirFilesContext(models.Model):
   id_category = models.ForeignKey(TdirCategories, db_column='id_category')
   id_file_context = models.CharField(max_length=20)
   n_file_context = models.CharField(max_length=150)
   coment = models.CharField(max_length=2000)
   id_user_db_ins = models.CharField(max_length=45)
   id_user_db_upd = models.CharField(max_length=45)
   id_user_sys_ins = models.CharField(max_length=45)
   id_user_sys_upd = models.CharField(max_length=45)
   date_ins = models.DateTimeField()
   date_last_upd = models.DateTimeField()
   class Meta:
       db_table = u'tdir_files_context'

This database table have Two primary keys and One foreign key. The Django Model handle this kind of database tables?

enter image description here


Solution

  • First, no table can have two primary keys. That's just not possible. I'll just assume yours has a primary key composed of two columns, id_category and id_file_context.

    Unfortunately, Django doesn't currently support models with composite primary keys, it can only handle tables with exactly one columns as their primary key.

    <plug type="shameless">There is work underway on making this possible with Django, see https://code.djangoproject.com/ticket/373 and my work on this from last Google Summer of Code: https://github.com/koniiiik/django </plug>

    Other than that though, ForeignKeys are perfectly fine with Django and I see no other problems with your table.