table prefix and question of possible solution

716 views
Skip to first unread message

Vitaliy

unread,
Feb 2, 2011, 9:19:41 AM2/2/11
to Django developers
I have a case where I have a lot of django sites(partially with the
same code) must run in a single mysql database

in order to avoid conflicts in django.auth, content-types and other
models tables for them must have unique prefix (since this data must
be isolated for each site)

Currently there is no way to set global(or per application) table
prefix (and all tickets that asked for this closed as invalid)

search in this groups gives nothing
So my question - was global table prefix for tables considered ?

and what is the way of doing this without this option(setting) in
framework ?


The only way I currently see is : handle "class_prepared" signal and
manually add prefix to table name :


from django.db.models.signals import class_prepared

def handle(sender, *args, **kwargs):
sender._meta.db_table = PREFIX + sender._meta.db_table

class_prepared.connect(handle)


BUT documentation says that class_prepard for internal only and
framework users should not use it?

is there any other option ?

Vitaliy

unread,
Feb 4, 2011, 3:36:24 AM2/4/11
to Django developers
so.. at least clas_prepared works
I made some plugable application that does what I need -
https://github.com/pydevua/django-table-prefix/tree/master/table_prefix

bug general question is class_prepared signal safe and good way to do
this ?

Dmitry Gladkov

unread,
Feb 7, 2011, 3:26:07 PM2/7/11
to Django developers
Hi Vitaliy,

I'm not a core developer myself, but I found your problem very
interesting. I looked at model
property code and couldn't find any clues about table prefix, so I
wrote a patch and opened a
ticket for your particular problem.

By the way, this is my first patch for Django, so I'm sure I've done
something terribly wrong,
so someone please take a look at it: http://code.djangoproject.com/ticket/15238


Best regards,
Dmitry Gladkov

Benjamin Wohlwend

unread,
Feb 7, 2011, 4:26:11 PM2/7/11
to django-d...@googlegroups.com
Hi Dmitry,

On Mon, Feb 7, 2011 at 9:26 PM, Dmitry Gladkov <dmitry....@gmail.com> wrote:

>
> By the way, this is my first patch for Django, so I'm sure I've done
> something terribly wrong,
> so someone please take a look at it: http://code.djangoproject.com/ticket/15238
>

Table prefixes have been proposed several times in the past, e.g.
Tickets #388, #891, #4999, #5000, and, to a certain degree, #13176.
This tickets are wontfix'ed for one reason or another, the most
relevant to your patch is probably Russell's comment in #5000[1]. If
the sentiment expressed in that comment hasn't fundamentally changed
in the meantime, chances to get this in are probably grim.

Regards,
Benjamin Wohlwend

[1]: http://code.djangoproject.com/ticket/5000#comment:5

Reply all
Reply to author
Forward
0 new messages