Имя таблицы в MySql - это пользовательские кредиты, а запрос, который генерирует django, работает без кавычек вокруг имени таблицы. Модель создается с помощью команды inspectdb из django, я пытаюсь django админ-панель в качестве менеджера БД.
models.py:
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
class Usercreds(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=20, blank=True, null=True)
password = models.CharField(max_length=20, blank=True, null=True)
class Meta:
managed = False
db_table = 'usercreds'
settings.py:
"""
Django settings for admindb project.
Generated by 'django-admin startproject' using Django 2.2.11.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(4n(txlca35l2nk$(#@^p9iin_a5m#&lvu7w=!-8tbb^7e0+33'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'dbmanagepsql',
'dbmanagemysql',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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',
]
ROOT_URLCONF = 'admindb.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'admindb.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testdb',
'USER': 'postgres',
'PASSWORD': 'wtfigo!!',
'HOST': 'localhost',
'PORT': '5432',
},
'mysql': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'init_command': 'SET default_storage_engine=INNODB',
'database': 'testdb',
'user' : 'root',
'password' : 'Ftpol018@',
},
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
Я получаю ошибку:
ProgrammingError at /admin/dbmanagemysql/usercreds/
relation "usercreds" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "usercreds"
Отслеживание от django:
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/dbmanagemysql/usercreds/
Django Version: 2.2.11
Python Version: 3.6.9
Installed Applications:
['dbmanagepsql',
'dbmanagemysql',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
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']
Traceback:
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
The above exception (relation "usercreds" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "usercreds"
^
) was the direct cause of the following exception:
File "/home/alex/.local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/alex/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/alex/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
606. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
223. return view(request, *args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in changelist_view
1685. cl = self.get_changelist_instance(request)
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_changelist_instance
744. sortable_by,
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in __init__
82. self.get_results(request)
File "/home/alex/.local/lib/python3.6/site-packages/django/contrib/admin/views/main.py" in get_results
210. result_count = paginator.count
File "/home/alex/.local/lib/python3.6/site-packages/django/utils/functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)
File "/home/alex/.local/lib/python3.6/site-packages/django/core/paginator.py" in count
91. return c()
File "/home/alex/.local/lib/python3.6/site-packages/django/db/models/query.py" in count
392. return self.query.get_count(using=self.db)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_count
504. number = obj.get_aggregation(using, ['__count'])['__count']
File "/home/alex/.local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_aggregation
489. result = compiler.execute_sql(SINGLE)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1140. cursor.execute(sql, params)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
99. return super().execute(sql, params)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
67. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
76. return executor(sql, params, many, context)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
File "/home/alex/.local/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/alex/.local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /admin/dbmanagemysql/usercreds/
Exception Value: relation "usercreds" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "usercreds"
^
Если есть какой-либо способ удалить кавычки или не генерировать запросы с кавычками, это решит проблему. Я попытался переименовать имя таблицы в models.py, но, похоже, ничего не работает. Если вы, ребята, знакомы с этим или каким-либо образом используете административную панель django в качестве пользовательского интерфейса менеджера БД для выполнения операций CRUD на любом БД, пожалуйста, помогите мне.