Joe
Joe

Reputation: 2997

Configure Django Database Routers

I am trying to connect a new Django site to legacy DBs. From everything I can gather I need to create a database router. The docs refer to creating an app_label in the meta section of the model. This is what the router would match to. I have also seen where people say this is not longer supported. I am racking my brain here please help!! Here is the code:

class CucRouter(object):
    def db_for_read(self, model):
        if model._meta.app_label == 'CUCMCDR':
            return 'CUCMCDR'
        return 'default'

That is the router function and is essentially the example from the docs. In the model I added this line:

 app_label = 'CUCMCDR'

This breaks the server with an error return that there is

"no app named CUCMCDR"

(which there shouldnt be. CUCMCDR is the name of the db)

Edit** I'm doing this all from the admin panel. I am trying to create just one APP. Maybe it would be easier to create another?

Upvotes: 0

Views: 218

Answers (1)

Joe
Joe

Reputation: 2997

SO I got it. If anyone else is running into this problem with multiple dbs it is an ordering issue. You need to change the second return from 'default' to 'None'

Upvotes: 0

Related Questions