0

When I edit my admin.py file

from django.contrib import admin
from .models import Packageweight

admin.site.register(Packageweight)

and the run python manage.py runserver and click in the admin page on Packageweight it throws this error

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/sybase_app/packageweight/

Django Version: 1.8
Python Version: 3.6.9
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog',
 'sybase_app')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/pd/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  616.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  233.             return view(request, *args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/home/pd/.local/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/pd/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in changelist_view
  1548.                 self.list_max_show_all, self.list_editable, self)
File "/home/pd/.local/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in __init__
  82.         self.get_results(request)
File "/home/pd/.local/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in get_results
  177.         result_count = paginator.count
File "/home/pd/.local/lib/python3.6/site-packages/django/core/paginator.py" in _get_count
  72.                 self._count = self.object_list.count()
File "/home/pd/.local/lib/python3.6/site-packages/django/db/models/query.py" in count
  318.         return self.query.get_count(using=self.db)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_count
  464.         number = obj.get_aggregation(using, ['__count'])['__count']
File "/home/pd/.local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_aggregation
  445.         result = compiler.execute_sql(SINGLE)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  829.             cursor.execute(sql, params)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  97.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/pd/.local/lib/python3.6/site-packages/django/utils/six.py" in reraise
  658.             raise value.with_traceback(tb)
File "/home/pd/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "/home/pd/.local/lib/python3.6/site-packages/sqlany_django/base.py" in execute
  98.             ret = self.cursor.execute(trace(query), trace(args))
File "/home/pd/.local/lib/python3.6/site-packages/sqlanydb.py" in execute
  796.         self.executemany(operation, [parameters])
File "/home/pd/.local/lib/python3.6/site-packages/sqlanydb.py" in executemany
  767.             bind_count = self.api.sqlany_num_params(self.stmt)
File "/home/pd/.local/lib/python3.6/site-packages/sqlanydb.py" in __stmt_get
  701.             self.handleerror(*self.parent.error())
File "/home/pd/.local/lib/python3.6/site-packages/sqlanydb.py" in handleerror
  695.             eh(self.parent, self, errorclass, errorvalue, sqlcode)
File "/home/pd/.local/lib/python3.6/site-packages/sqlanydb.py" in standardErrorHandler
  379.         raise errorclass(errorvalue,sqlcode)

Exception Type: OperationalError at /admin/sybase_app/packageweight/
Exception Value: (b"Table 'sybase_app_packageweight' not found", -141)

How could I fix it?

Ubuntu 18.04

xralf
  • 3,312
  • 45
  • 129
  • 200
  • I solved it with `db_table` [attribute](https://docs.djangoproject.com/en/4.0/ref/models/options/), but if you have some explanation, or how to avoid that the generated models with `python manage.py inspect db` should be adjusted and every should have `db_table` attribute, I would appreciate it. In that database there are hundreds of tables. – xralf Jan 22 '22 at 17:44
  • What did you pass in `db_table` attribute? – aaron Jan 27 '22 at 16:58
  • to `class Meta:` – xralf Jan 28 '22 at 07:16
  • I mean what is the value? – aaron Jan 28 '22 at 07:30
  • `Packageweight` works, but we started rather using the copy of a table `PackageweightTest`. It didn't work before because django was using some prefix of the table for the generated model. – xralf Jan 28 '22 at 08:36
  • That's by convention. I still don't know what's the expected result here. – aaron Jan 28 '22 at 11:05
  • I will generate more models with `python manage.py inspect db` from the database later. So, I have to create `db_table` attribute for each model? Isn't there some settings for it? – xralf Jan 28 '22 at 11:32
  • What do you want to set it to? – aaron Jan 28 '22 at 11:44
  • The table name shouldn't be `sybase_app_packageweight`, but only `packageweight` – xralf Jan 28 '22 at 11:47
  • `python manage.py inspectdb` already sets `db_table` based on the table name in the database. What's your workflow? – aaron Jan 28 '22 at 12:48

0 Answers0