The Wayback Machine - https://web.archive.org/web/20200621140229/https://github.com/gunthercox/ChatterBot/issues/1619
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Django] Using other database than the "default" #1619

Open
bkawakami opened this issue Feb 12, 2019 · 1 comment
Open

[Django] Using other database than the "default" #1619

bkawakami opened this issue Feb 12, 2019 · 1 comment
Labels

Comments

@bkawakami
Copy link

@bkawakami bkawakami commented Feb 12, 2019

I am trying to integrate ChatterBot into my Django application, but I would like ChatterBot to work in a database other than the default.

Django itself gives you the option of model routing when you want to use multiple databases:

https://docs.djangoproject.com/en/2.1/topics/db/multi-db/

But even following the Django standard, ChatterBot insists on running only on the default database.

My settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'chatbot_db': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'chatbot.sqlite3'),
    }
}


DATABASE_ROUTERS = [
    'myapp.chatbot_router.ChatbotRouter'
]

And my chatbot_router.py:

class ChatbotRouter:
    def db_for_read(self, model, **hints):
        if model._meta.app_label == 'django_chatterbot':
            return "chatbot_db"
        return None

    def db_for_write(self, model, **hints):
        if model._meta.app_label == 'django_chatterbot':
            return "chatbot_db"
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        if app_label == 'django_chatterbot':
            return "chatbot_db "
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the auth app is involved.
        """
        if obj1._meta.app_label == 'django_chatterbot' or \
                obj2._meta.app_label == 'django_chatterbot':
            return True
        return None

Someone know how to do that?

@gunthercox
Copy link
Owner

@gunthercox gunthercox commented Feb 20, 2019

I'll have to double check how this can be done, but I am fairly certain that it requires a change to the models being used to specify the database they are for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.