Django prompts that the mysql version is too low: django.db.utils.NotSupportedError_ MySQL 8 or later is required (found 5.7.26).

Django hints MySQL version too low: Django. Db. Utils. NotSupportedError: MySQL 8 or later is required (found 5.7.26).

Because MySQL 5.7 and below is a free database, and after 8.0 it is charged. Using a free database is more reassuring, and there is no difference in use. This tip is just a Django version detection tip, 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 annotate it:

 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)

Execute the command to generate the database migration file first:

python .\manage.py makemigrations

Then write the data entity class:

from django.db import models

# Create your models here.
"""Carousel chart model"""


class Banner(models.Model):
    # model fields
    image_url = models.CharField(max_length=255, verbose_name="Ad Image")
    link = models.CharField(max_length=500, verbose_name="advertising link")
    remark = models.TextField(verbose_name="Remark")
    is_show = models.BooleanField(verbose_name="Whether to display", 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", null=True, blank=True)
    is_delete = models.BooleanField(verbose_name="Tombstone", default=False)

    # Table information
    class Meta:
        db_table = "dj_banner"
        verbose_name = "carousel ads"
        verbose_name_plural = verbose_name

    # Custom display fields
    def __str__(self):
        return self.title

Set 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',
    },
}

Finally, migrate to the database and execute the command:

python .\manage.py migrate

There are tables in the database that come with Django and tables that create entity classes: