MySQL 警告:#1265 第 1 行的“pdd”列的数据被截断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27077157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:11:43  来源:igfitidea点击:

Warning: #1265 Data truncated for column 'pdd' at row 1

mysql

提问by Nick

I am having trouble trying to set the PDD(patient death date) to null on PHPMYADMIN until such death date comes; also on the client end then I can check for NULLdata to use it.

我在尝试将PDDPHPMYADMIN 上的(患者死亡日期)设置为 null时遇到问题,直到这样的死亡日期到来;同样在客户端,然后我可以检查NULL数据以使用它。

Could anyone suggest me a solution, please ?

任何人都可以建议我一个解决方案吗?

patientnhs_no   hospital_no sex     name    surname     dob     address     pls  pdd    
1001001001      6000001      m     john     smith   1941-01-01  Bournmouth  1    0000-00-00

(PDD should be null if is alive or death date if died)

(如果是活着的,则 PDD 应该是空的,如果死了,则死亡日期应该是空的)

采纳答案by Nick

As the message error says, you need to Increase the length of your column to fit the length of the data you are trying to insert (0000-00-00)

正如消息错误所说,您需要增加列的长度以适应您尝试插入的数据的长度(0000-00-00)

EDIT 1:

编辑 1

Following your comment, I run a test table:

根据您的评论,我运行了一个测试表:

mysql> create table testDate(id int(2) not null auto_increment, pdd date default null, primary key(id));
Query OK, 0 rows affected (0.20 sec)

Insertion:

插入:

mysql> insert into testDate values(1,'0000-00-00');
Query OK, 1 row affected (0.06 sec)

EDIT 2:

编辑2:

So, aparently you want to insert a NULL value to pddfield as your comment states ? You can do that in 2 ways like this:

那么,显然您想在pdd您的评论中向字段插入一个 NULL 值?您可以通过以下两种方式做到这一点:

Method 1:

方法一:

mysql> insert into testDate values(2,'');
Query OK, 1 row affected, 1 warning (0.06 sec)

Method 2:

方法二:

mysql> insert into testDate values(3,NULL);
Query OK, 1 row affected (0.07 sec)

EDIT 3:

编辑 3:

You failed to change the default value of pddfield. Here is the syntax how to do it (in my case, I set it to NULL in the start, now I will change it to NOT NULL)

您未能更改pdd字段的默认值。这是如何做到这一点的语法(在我的情况下,我在开始时将其设置为 NULL,现在我将其更改为 NOT NULL)

mysql> alter table testDate modify pdd date not null;
Query OK, 3 rows affected, 1 warning (0.60 sec)
Records: 3  Duplicates: 0  Warnings: 1

回答by Wrikken

You are most likely pushing a string'NULL'to the table, rather then an actual NULL, but other things may be going on as well, an illustration:

您最有可能将一个字符串'NULL'到桌子上,而不是一个实际的NULL,但其他事情也可能发生,例如:

mysql> CREATE TABLE date_test (pdd DATE NOT NULL);
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO date_test VALUES (NULL);
ERROR 1048 (23000): Column 'pdd' cannot be null
mysql> INSERT INTO date_test VALUES ('NULL');
Query OK, 1 row affected, 1 warning (0.05 sec)

mysql> show warnings;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1265 | Data truncated for column 'pdd' at row 1 |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM date_test;
+------------+
| pdd        |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

mysql> ALTER TABLE date_test MODIFY COLUMN pdd DATE NULL;
Query OK, 1 row affected (0.15 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> INSERT INTO date_test VALUES (NULL);
Query OK, 1 row affected (0.06 sec)

mysql> SELECT * FROM date_test;
+------------+
| pdd        |
+------------+
| 0000-00-00 |
| NULL       |
+------------+
2 rows in set (0.00 sec)