Wednesday, January 26, 2011

Re: Django: Object Oriented or Relational Database?


On 26 Jan 2011, at 11:55, Daniel Roseman wrote:

This is what's known as the object-relational impedance mismatch [1]. Unfortunately, as you've noticed, OO concepts don't map completely cleanly onto the relational model, and this is an issue with all systems that attempt to do it. Django does what it can to smooth over the gaps, but can't always do everything.

Thanks for the link; interesting reading.

However, you should not be getting circular dependencies. Can you provide some examples? One place where I often see them is when two models in separate applications are related via ForeignKey, and the developer has imported each model into the other's models.py. But it isn't necessary to import them at all, as you can refer to models via strings: 

    myfkfield = models.ForeignKey('otherapp.OtherModel')

so no circular dependency is declared. Does that solve your problem? If not, some examples will be helpful.


I've used the string form for forward references of models; but I still seem to get problems when performing the initial migration (using South) of the database as the table to which the forward reference points does not exist at the time of creating the initial table.

I've just tried using a basic syncdb and that works fine.  I presume I'm seeing problems as South's migrations work one app at a time; in contrast to syncdb that seems to install the whole project - only worrying about dependencies at the end.

Still; I feel circular dependencies are bad; even work arounds are possible.

Is there a recommended path to take with Django?

Kind regards,

aid



No comments:

Post a Comment