etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.21k stars 129 forks source link

Support Multi-Database configuration #306

Open abaruchi opened 11 months ago

abaruchi commented 11 months ago

Currently, Django-Watson only supports a configuration with a single database. When running the command python manage.py buildwatson, if a default database isn't configured, you get an error:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "venv/lib/python3.10/site-packages/django/core/management/base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "venv/lib/python3.10/site-packages/django/core/management/base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "venv/lib/python3.10/site-packages/watson/management/commands/buildwatson.py", line 187, in handle
    refreshed_model_count += rebuild_index_for_model(
  File "venv/lib/python3.10/site-packages/watson/management/commands/buildwatson.py", line 72, in rebuild_index_for_model
    with transaction.atomic():
  File "venv/lib/python3.10/site-packages/django/db/transaction.py", line 189, in __enter__
    if not connection.get_autocommit():
  File "venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 400, in get_autocommit
    self.ensure_connection()
  File "venv/lib/python3.10/site-packages/django/db/backends/dummy/base.py", line 20, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Django-Watson should add an option to indicate which database the command suppose to use.