Django“ / admin / login /上没有此表:OperationalError:institutemanagement_customuser”

时间:2019-08-28 08:08:56

标签: python django

我想扩展默认的Django用户模型。我已经为此目的完成了此代码,并千方百计地进行了迁移,但是遇到了相同的错误“ / admin / login /上没有这样的表:instantmanagement_customuser”的“ OperationalError”。下面是我的settings.py和models.py文件

settings.py

"""
Django settings for studentmanager project.

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

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 = '!uc)2%be(w4c4%xn^3z@pmj5l2$(zor_2l1_g%bu!ggv3z^hy%'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'institutemanagement.apps.InstitutemanagementConfig',
]

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 = 'studentmanager.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 = 'studentmanager.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/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/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 = 'Europe/Bucharest'

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/'

LOGIN_URL = 'institutemanagement-login'

AUTH_USER_MODEL = 'institutemanagement.CustomUser'

models.py

from django.core.validators import MinLengthValidator, MaxLengthValidator, MinValueValidator, MaxValueValidator
from django.db import models
from datetime import date
from django.contrib.auth.models import AbstractUser


grades = [
    (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'),
    (8, '8'), (9, '9'), (10, '10'), ('Absent', 'Absent')
]

user_type = [('S', 'Secretary'), ('T', 'Teacher'), ('S', 'Student')]

class CustomUser(AbstractUser):
   type = models.IntegerField(choices=user_type, default='A')


class Student(models.Model):
    first_name = models.CharField(max_length=20, null=True)
    middle_name = models.CharField(max_length=20, blank=True, null=True)
    last_name = models.CharField(max_length=20, null=True)
    CNP = models.CharField(max_length=13, null=True)
    year_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1960), MaxValueValidator(2020)],
                                                null=True)
    month_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(12)], null=True)
    date_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(31)], null=True)
    phone_number = models.CharField(max_length=13, null=True)
    picture = models.ImageField(null=True)
    email = models.EmailField(null=True)
    year_of_study = models.PositiveSmallIntegerField(validators=[MinValueValidator(1), MaxValueValidator(4)], null=True)


class Teacher(models.Model):

    first_name = models.CharField(max_length=20, null=True)
    middle_name = models.CharField(max_length=20, blank=True, null=True)
    last_name = models.CharField(max_length=20, null=True)
    CNP = models.CharField(max_length=13, null=True)
    year_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1940), MaxValueValidator(2020)],
                                                null=True)
    month_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(12)], null=True)
    date_of_birth = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(31)], null=True)
    phone_number = models.CharField(max_length=13, null=True)
    email = models.EmailField(null=True)
    picture = models.ImageField(null=True)


class Subject(models.Model):
    name = models.CharField(max_length=20)
    media = models.FileField(upload_to='media/Subject.name', null=True, blank=True)
    description = models.TextField(blank=True)
    professor = models.ForeignKey(Teacher, on_delete=models.CASCADE)
    year = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(4)], null=True)
    semester = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(2)], null=True)


class Grade(models.Model):
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
    student = models.ForeignKey(Student, on_delete=models.CASCADE)
    grade = models.IntegerField(choices=grades, default='Absent')
    date = models.DateField('Data Examen', default=date.today)

我希望登录,但是在提交登录表单时,它显示错误消息“找不到CustomerUser”表

0 个答案:

没有答案