MariaDB 显示警告而不是错误

MariaDB shows warnings instead of errors(MariaDB 显示警告而不是错误)
本文介绍了MariaDB 显示警告而不是错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MariaDB 版本:10.6.4-MariaDB-1:10.6.4+maria~focal

MariaDB version: 10.6.4-MariaDB-1:10.6.4+maria~focal

SQL:

insert ignore into `step` (is_draft, created_by) values ('1', 2);

收到警告:

MariaDB [kite]> show warningsG
*************************** 1. row ***************************
  Level: Warning
   Code: 1364
Message: Field 'course_id' doesn't have a default value
*************************** 2. row ***************************
  Level: Warning
   Code: 1364
Message: Field 'title' doesn't have a default value
*************************** 3. row ***************************
  Level: Warning
   Code: 1452
Message: Cannot add or update a child row: a foreign key constraint fails (`kite`.`step`, CONSTRAINT `step_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `course` (`course_id`) ON DELETE CASCADE ON UPDATE CASCADE)
3 rows in set (0.000 sec)

如果约束失败,我预计会出现错误.事实上,它曾经是,但不是现在.如何启用错误而不是警告?

I'm expecting to have an error if a constraint fails. In fact, it used to, but not now. How to enable errors instead of warnings?

在 Google 上搜索 SQL_MODE 并尝试了不同的组合,但没有成功:

Googled about SQL_MODE and tried different combinations, but no luck:

MariaDB [kite]> SELECT @@SQL_MODE, @@GLOBAL.SQL_MODEG
*************************** 1. row ***************************
       @@SQL_MODE: STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
@@GLOBAL.SQL_MODE: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

提前致谢!

更新:看起来问题出在 ignore 关键字中.如果我删除 - 它会按预期工作.

UPDATE: Looks like the problem is in ignore keyword. If I remove - it works as expected.

推荐答案

如果你想要错误而不是警告,那么不要使用 ignore.

If you want errors instead of warnings, then don't use ignore.

https://mariadb.com/kb/en/insert-ignore/ 说:

通过使用 IGNORE 关键字,所有错误都将转换为警告,这不会停止插入其他行.

By using the IGNORE keyword all errors are converted to warnings, which will not stop inserts of additional rows.

这篇关于MariaDB 显示警告而不是错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)