1. 程式人生 > >?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'

?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'

問題

django專案中,執行python manage migrate
這裡寫圖片描述

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.10/ref/databases/#mysql-sql-mode

解決

在settings中,在DATABASES變數定義處下面新增

DATABASES['OPTIONS']['init_command'] = "SET sql_mode='STRICT_TRANS_TABLES'"

或者在DATABASES變數定義時,新增上面命令中所示的鍵值對。
這裡寫圖片描述