Django prompts that the mysql version is too low: django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26).
Django prompts that the mysql version is too low: django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26).
Because mysql5.7 and below are free databases, and after 8.0 they are charged. It is more secure to use a free database, and there is no difference in usage. This prompt is just a Django version detection prompt, just comment it out.
Global search function:
check_database_version_supported()
The file path is:D:\Python\web_project\dj01\venv\Lib\site-packages\django\db\backends\base\base.py
Find the second one, which is the one used, and comment it out:
def init_connection_state(self):
"""Initialize the database connection settings."""
global RAN_DB_VERSION_CHECK
if self.alias not in RAN_DB_VERSION_CHECK:
# self.check_database_version_supported()
RAN_DB_VERSION_CHECK.add(self.alias)
First execute the command to generate database migration files: python .\manage.py makemigrations
Then write the data entity class:
from django.db import models
# Create your models here.
"""Carousel model"""
class Banner(models.Model):
# Model Fields
image_url = models.CharField(max_length=255, verbose_name="Advertising images")
link = models.CharField(max_length=500, verbose_name="Advertising link")
remark = models.TextField(verbose_name="notes")
is_show = models.BooleanField(verbose_name="Is it displayed", default=False)
orders = models.IntegerField(default=1, verbose_name="sort")
title = models.CharField(max_length=500, verbose_name="Ad Title")
image = models.ImageField(upload_to="banner", verbose_name="Carousel chart", null=True, blank=True)
is_delete = models.BooleanField(verbose_name="tombstone", default=False)
# table information
class Meta:
db_table = "dj_banner"
verbose_name = "Carousel advertising"
verbose_name_plural = verbose_name
# Custom Display Fields
def __str__(self):
return self.title
Set up the database connection configuration:settings/dev.py
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# },
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dj01',
'HOST': '127.0.0.1',
'PORT': 3306,
'USER': 'root',
'PASSWORD': 'root',
},
}
The last step is to migrate to the database and execute the command:python .\manage.py migrate
There are tables that come with Django and tables with created entity classes in the database: