[multidb] emit_pre_migrate_signal / emit_post_migrate_signal in Django 1.8

103 views
Skip to first unread message

Marcin Nowak

unread,
Aug 5, 2015, 1:08:05 PM8/5/15
to Django developers (Contributions to Django itself)
Hi, it's me again.

I'm managing migrations myself without using builtin migrations.

My project is using many databases and I'm calling schema migration separately for each database, providing database alias as a command argument. 
I'm also emitting pre- and post- migrate signals.

The problem is with new Django (teste with 1.8.3). 

When updating schema for 'default' database (which contains all Django-related tables, like auth, contenttypes, and so on), evertyhing works well.

But when updating other databases (without auth, contenttypes, etc), and when emitting post migrate signal with database alias other than 'default', Django is reading all registered apps and calls (for example) "django.auth.management.create_permissions", even if Permission model (or ContentType) is routed to 'default' alias. As a result Django tries to insert data into tables whose does not exists in specified database.

I can bypass emitting signals for databases other than 'default', but the problem still remains in Django itself. 
I think that Django should use database routers to check whether model is managed/writeable.

Let's assume that we have two databases: 'default' an 'other'.
Signal is emitting with db alias 'other'.
Then tries to get ContentType using='other'. But the 'other' database has no such table.

Is that feature or bug?
Should I create contrib.* tables for each database?

Kind Regards,
Marcin

Tim Graham

unread,
Aug 5, 2015, 1:42:16 PM8/5/15
to Django developers (Contributions to Django itself)
There is a check a few lines above the snippet you linked for "allow_migrate_model('other', Permission)". Is that returning the correct result? I don't think you can create permissions in the 'other' db without content types since they are linked by a foreign key.

p.s. "Is it a bug" questions should go to django-users, thanks!

Marcin Nowak

unread,
Aug 5, 2015, 3:08:56 PM8/5/15
to Django developers (Contributions to Django itself)


On Wednesday, August 5, 2015 at 7:42:16 PM UTC+2, Tim Graham wrote:
There is a check a few lines above the snippet you linked for "allow_migrate_model('other', Permission)". Is that returning the correct result? I don't think you can create permissions in the 'other' db without content types since they are linked by a foreign key.


Probably you've got the point! I didn't pay enough attention to this method and didn't saw this check.
 
p.s. "Is it a bug" questions should go to django-users, thanks!


Yes, sir! Just thought that there is a better place to ask about internals, but I was wrong I suppose.
 

Thanks, Tim!
Marcin
Reply all
Reply to author
Forward
0 new messages