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

table not found for models stored in secondary database #25

Open
moccand opened this issue Jan 1, 2022 · 2 comments
Open

table not found for models stored in secondary database #25

moccand opened this issue Jan 1, 2022 · 2 comments

Comments

@moccand
Copy link

moccand commented Jan 1, 2022

Some of my models are store in a dedicated database and using :

in settings.py :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },
    'catalog': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        ...
        'PORT': '5432',
    }

in models.py :

    class Meta:
        managed = False
        db_table = '__mytable'

and in my modelAdmin classes :
using = 'catalog'

makes an exception : no such table: __mytable

@blag
Copy link
Collaborator

blag commented Jan 2, 2022

Please post the full traceback. It's impossible to tell what the issue could be with just the information provided so far.

Is there a particular reason you think it's a problem due to django-admin-row-actions?

Have you verified that you setup your database routers correctly?

@moccand
Copy link
Author

moccand commented Jan 2, 2022

the method in my ModelAdmin :

    def get_row_actions(self, obj):
        row_actions = [
            {
                'label': 'Activer',
                'action': 'set_actif',
                'enabled': obj.actif == False,
            }, {
                'label': 'Desactiver',
                'action': 'set_inactif',
                'enabled': obj.actif == True,
            },
        ]
        row_actions += super(MyCoucheModelAdmin, self).get_row_actions(obj)
        return row_actions

the error only appends when the action is laucnh. the model and the strandard admin functions.
then the error is (the real table name is '__couches') :

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/catalogue/couche/1771/rowactions/set_inactif/

Django Version: 3.2.9
Python Version: 3.8.12
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.gis',
 'rangefilter',
 'django_admin_listfilter_dropdown',
 'django_admin_row_actions',
 'django_object_actions',
 'admin_reorder',
 'catalogue']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'admin_reorder.middleware.ModelAdminReorder']



Traceback (most recent call last):
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
    return Database.Cursor.execute(self, query, params)

The above exception (no such table: __couches) was the direct cause of the following exception:
  File "C:\Users\myproject\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\myproject\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\myproject\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\myproject\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\myproject\lib\site-packages\django\contrib\admin\sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "C:\Users\myproject\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\myproject\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\myproject\lib\site-packages\django_admin_row_actions\views.py", line 18, in get
    obj = self.get_object()
  File "C:\Users\myproject\lib\site-packages\django\views\generic\detail.py", line 52, in get_object
    obj = queryset.get()
  File "C:\Users\myproject\lib\site-packages\django\db\models\query.py", line 431, in get
    num = len(clone)
  File "C:\Users\myproject\lib\site-packages\django\db\models\query.py", line 262, in __len__
    self._fetch_all()
  File "C:\Users\myproject\lib\site-packages\django\db\models\query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Users\myproject\lib\site-packages\django\db\models\query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "C:\Users\myproject\lib\site-packages\django\db\models\sql\compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\myproject\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\myproject\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\myproject\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
    return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/catalogue/couche/1771/rowactions/set_inactif/
Exception Value: no such table: __couches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants