Как я могу увидеть базу данных django, которая самостоятельно хранит значения с сервера сайта? - PullRequest
0 голосов
/ 28 апреля 2020

Я пытаюсь сохранить тег вопросов в sqlite3 из Django, но всякий раз, когда я пытаюсь нажать на Вопрос в / admin /, появляется сообщение об ошибке:

изображение ошибки в случае изображение не отображается, это ошибка {

OperationalError at /admin/userinfo/question/
no such table: userinfo_question
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/userinfo/question/
Django Version: 3.0.5
Exception Type: OperationalError
Exception Value:    
no such table: userinfo_question

}

Я уже пробовал

  1. изменение пути sqlite3 в настройках (ошибка не устранена та же ошибка)

  2. python manage.py migrate --run-syncdb (после применения makemigrations) (ошибка миграции не устранена)

это было написано при выполнении миграций

Creating tables...
Running deferred SQL...

, поэтому я думаю, что таблица создает, но не отображает (может быть)

это мой models.py '' '

from django.db import models


# Create your models here.

class Question(models.Model):
    prob_link = models.CharField(max_length=500, default='')
    prob_level = models.CharField(max_length=1)
    prob_rating = models.IntegerField()
    expression_parsing = models.BooleanField(default=False)
    fft = models.BooleanField(default=False)
    two_pointers = models.BooleanField(default=False)
    binary_search = models.BooleanField(default=False)
    dsu = models.BooleanField(default=False)
    strings = models.BooleanField(default=False)
    number_theory = models.BooleanField(default=False)
    data_structures = models.BooleanField(default=False)
    hashing = models.BooleanField(default=False)
    shortest_paths = models.BooleanField(default=False)
    matrices = models.BooleanField(default=False)
    string_suffix_structures = models.BooleanField(default=False)
    graph_matchings = models.BooleanField(default=False)
    dp = models.BooleanField(default=False)
    dfs_and_similar = models.BooleanField(default=False)
    meet_in_the_middle = models.BooleanField(default=False)
    games = models.BooleanField(default=False)
    schedules = models.BooleanField(default=False)
    constructive_algorithms = models.BooleanField(default=False)
    greedy = models.BooleanField(default=False)
    bitmasks = models.BooleanField(default=False)
    divide_and_conquer = models.BooleanField(default=False)
    flows = models.BooleanField(default=False)
    geometry = models.BooleanField(default=False)
    math = models.BooleanField(default=False)
    sortings = models.BooleanField(default=False)
    ternary_search = models.BooleanField(default=False)
    combinatorics = models.BooleanField(default=False)
    brute_force = models.BooleanField(default=False)
    implementation = models.BooleanField(default=False)
    sat_2 = models.BooleanField(default=False)
    trees = models.BooleanField(default=False)
    probabilities = models.BooleanField(default=False)
    graphs = models.BooleanField(default=False)
    chinese_remainder_theorem = models.BooleanField(default=False)
    interactive = models.BooleanField(default=False)
    other_tag = models.BooleanField(default=False)
    special_problem = models.BooleanField(default=False)

'' 'здесь это settings.py

"""
Django settings for codeforces_crawler project.

Generated by 'django-admin startproject' using Django 3.0.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'sp_$b%e_g1v)eam^rqlef5v8#@&6qhxw1&2f6me^c!b^v+rkwl'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'userinfo.apps.UserinfoConfig',
    '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 = 'codeforces_crawler.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 = 'codeforces_crawler.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

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


# Password validation
# https://docs.djangoproject.com/en/3.0/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/3.0/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/3.0/howto/static-files/

STATIC_URL = '/static/'

это views.py

from django.shortcuts import render
from .scraping import scrape


def index(request):
    return render(request, 'userinfo/index.html')


def detail(request):
    user = request.POST['user']  # user is the name of the input
    # rank,color,ar,institute,ac,wa,tle,rte,mle,challenged,cpe,skipped,ile,other = scrape(user)
    verdict = scrape(user)
    if verdict == False:
        exists = verdict
        return render(request, 'userinfo/detail.html', {'exists': exists})
    else:
        exists = verdict[0]
        rank = verdict[1]
        color = verdict[2]
        ar = verdict[3]
        institute = verdict[4]
        ac = verdict[5]
        wa = verdict[6]
        tle = verdict[7]
        rte = verdict[8]
        mle = verdict[9]
        challenged = verdict[10]
        cpe = verdict[11]
        skipped = verdict[12]
        ile = verdict[13]
        other = verdict[14]
        rating = verdict[15]
        return render(request, 'userinfo/detail.html',
                      {'exists': exists, 'user': user, 'rank': rank, 'color': color, 'ar': ar, 'institute': institute,
                       'ac': ac, 'wa': wa, 'tle': tle, 'rte': rte, 'mle': mle, 'challenged': challenged
                          , 'cpe': cpe, 'skipped': skipped, 'ile': ile, 'other': other, 'rating': rating})
        # return render(request, 'userinfo/detail.html', {'user': user, 'verdict':verdict,})

это admin.py' ''

from django.contrib import admin
from .models import Question

# Register your models here.
admin.site.register(Question)

'' 'это url.py

from django.urls import path
from . import views

app_name = 'userinfo'
urlpatterns = [
    path('',views.index, name='index'),
    path('detail/',views.detail,name='detail'),
]

или если есть какой-либо другой способ узнать, какие вопросы были добавлены в мою базу данных.

Невозможно решить эту проблему эр ror за последние 3 дня. Заранее благодарим за помощь.

1 Ответ

1 голос
/ 28 апреля 2020

Сообщение об ошибке «нет такой таблицы: userinfo_question» указывает, что Django не превратил представление вашей модели в таблицы в вашей базе данных.

Убедитесь, что информация о пользователе вашего приложения указана в INSTALLED_APPS в settings.py.

Вы также должны запустить makemigrations перед запуском migrate

python manage.py makemigrations
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...