Home  >  Q&A  >  body text

yii2 - MySQL [23000] Column cannot be null

MySQL 表结构字段 face char(20) NOT NULL 。
插入数据的时候,当face值设置为NULL,报错 MySQL SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'face' cannot be null

MariaDB [db2_dalu]> select version();
+--------------------+
| version()          |
+--------------------+
| 5.5.41-MariaDB-log |
+--------------------+
1 row in set (0.00 sec)

但是我本地却没有这样的情况,本地的MySQL版本:

mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.17-log |
+------------+
1 row in set (0.00 sec)

mysql>
PHP中文网PHP中文网2743 days ago753

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 14:59:55

    What’s the point of posting this? It’s obviously a problem during insertion. You should post the inserted code.
    And I think there is nothing wrong with the prompt, because you require that it cannot be empty. When you insert a null value, it would be strange not to remind you.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 14:59:55

    Obviously not null is set, so null values ​​cannot be inserted. You said before that the local version can be inserted. This must be a supernatural phenomenon.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:59:55

    Is it because the higher version has stricter restrictions?

    reply
    0
  • 迷茫

    迷茫2017-04-17 14:59:55

    This. . Whether in MySQL's strict mode or non-strict mode, you can set whether to remind you of null values.

    reply
    0
  • Cancelreply