0

So I am trying to stand up a Django site that will query my DBs and return reports. I have 5 legacy DBs that need to be imported. I set one as default and ran inspectdb. This one imported correctly and now is all set. I ran inspectdb against the next, got the models but when I click on the link in admin panel I get an error. My default db name is app2, and the second db im working with is cucm. There error says that there is no db at app2.cucm - Why is django trying to go to app2.cucm instead of just going to cucm like it should????? settings.py file

DATABASES = {
      'cucm': {
          'NAME': 'CUCM'
          'ENGINE': 'django.db.backends.mysql',
          'USER': 'user'
          'PASSWORD': 'PASSWORD'
          'HOST': 'IPADDRESS'
          'PORT': '111111'
        },

'default': {
    'NAME': 'app2',
    'ENGINE': 'django.db.backends.mysql',
    'USER': 'user',
    'PASSWORD': 'PASSWORD',
    'HOST': 'IPADDRESS',
    'PORT': '1111',
  },
}  

Full error looks like so:

The pathname '/root/IPNV/django-test/src/reports/models.py' of this watch at 0x7fbe145cef50> dir=False > has probably changed and couldn't be updated, so it cannot be trusted anymore. To fix this error move directories/files only between watched parents directories, in this case e.g. put a watch on '/root/IPNV/django-test/src/reports'

I know the syntax is not perfect above, I retyped it quickly. It is worth noting that all the DBs are on the same host. So all the fields for every db are identical except the name

This is the error form the Django admin panel: Exception Value:

(1146, "Table 'app2.CDR' doesn't exist")

I think the problem is in the routing. 'CDR' is a table in cucm db not app2. I have not created any db routing yet. I was hoping the default would work

Joe
  • 2,641
  • 5
  • 22
  • 43

1 Answers1

0

Perhaps it has to do with how you're calling the db. If you have multiple dbs, you have to explicitly say which one you are using. For example, if the model was person, you might say:

Person.objects.using(dbname)
mewpeter
  • 26
  • 1
  • 4
  • Yeah that sounds like the problem but where would I enter that line of code?? – Joe May 16 '17 at 15:15
  • Wherever you make a query to the db. So if you had a view that printed a list of all the people in the Person Model and wanted to use db1, you would just say: Person.objects.using(db1).all(). To switch between dbs, you could use a form for that view and pass the user input into the using call. – mewpeter May 16 '17 at 15:34
  • 1
    I feel like there must be a better way. My views are not really built yet because I'm working in the admin panel. Everything works perfect with the 'default' db. – Joe May 16 '17 at 15:38
  • Right, you either would need to take this manual approach or create custom db routing. Is there a rule for when you would use one db over another? – mewpeter May 16 '17 at 15:44
  • The admin panel might be a specific issue. The django docs say "Django’s admin doesn’t have any explicit support for multiple databases. If you want to provide an admin interface for a model on a database other than that specified by your router chain, you’ll need to write custom ModelAdmin classes that will direct the admin to use a specific database for content." https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#topics-db-multi-db-routing – mewpeter May 16 '17 at 16:17
  • Ok. I have five total databases each with a couple dozen tables. So I need to make sure that each table ties to the correct db. The docs on creating db routing are a little confusing but I will look more into it – Joe May 16 '17 at 17:05