gpt4 book ai didi

mysql - 警告 : ? : (mysql. W002)

转载 作者:行者123 更新时间:2023-12-04 08:40:32 24 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

10 个月前关闭。




Improve this question




我是 django 的新手,只是想更改为 MySQL 数据库,但是即使我已经为它添加了代码,这个警告仍然存在。
我的设置.py

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "mysql_database",
"USER": "root",
"PASSWORD": "",
"OPTION": {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1",
'charset': 'utf8mb4',
"autocommit": True,
}

}
}
警告
WARNINGS:
?: (mysql.W002) MariaDB Strict Mode is not set for database connection 'default'
HINT: MariaDB's Strict Mode fixes many data integrity problems in MariaDB, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/3.1/ref/databases/#mysql-sql-mode
尝试了几次重置和迁移,但没有奏效。

最佳答案

您收到的错误消息为您提供了解决方案的元素。如果你去那个链接 https://docs.djangoproject.com/en/3.1/ref/databases/#mysql-sql-mode你会注意到它是 OPTIONS (复数)而不是 OPTION (单例的):

If you need to customize the SQL mode, you can set the sql_mode variable like other MySQL options: either in a config file or with the entry 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" in the OPTIONS part of your database configuration in DATABASES.


作为良好的编码习惯,字典通常以复数形式保存,如 DATABASESOPTIONS .

关于mysql - 警告 : ? : (mysql. W002),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64588187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com