Friday, December 15, 2017

Let the model define the database with a custom router

I'm porting a website from Django 1.6.x to 1.11 and I'm hitting a problem with my custom router. Some models define a custom attribute defining which database it will reside in:

class MyModel(models.Model):
    DATABASE_NAME
= "foo"

This worked in our custom router in 1.6.x but not in 1.11. The router accesses it like:

        if hasattr(model,'DATABASE_NAME'):
           
return model.DATABASE_NAME == db

Inside the allow_migrate function of my router, the custom attribute DATABASE_NAME doesn't exist in the model in 1.11 but it was there in 1.6.x, if that makes sense.

Any suggestions for a different implementation? I want my models to define the physical database they are in.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7024c17a-0190-4c84-99df-76689e6a0af5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment