Django中配置MariaDB数据库。配置文件如下:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'database_name',
        'PORT': 3306,
        "HOST": '127.0.0.1',
        'USER': 'username',
        'PASSWORD': 'password',
        'OPTIONS': {
            'autocommit': True,
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        }
    }
}

'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"是解决警告:

WARNINGS:WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-01-07
  • 2022-03-01
  • 2021-09-30
  • 2022-01-20
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2022-01-18
  • 2021-12-01
  • 2021-10-08
  • 2021-05-28
  • 2021-11-21
相关资源
相似解决方案