2014-11-22 13 views
6

Ho problemi a cercare di impostare il PDD (data di morte del paziente) su null su PHPMYADMIN fino a quando tale data di morte non viene; anche sul lato client posso controllare i dati NULL per usarlo.Avviso: # 1265 Dati troncati per la colonna 'pdd' alla riga 1

Qualcuno potrebbe suggerirmi una soluzione, per favore?

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 dovrebbe essere nullo se è vivo o la morte data, se è morto)

risposta

3

Come dice il messaggio di errore, è necessario aumentare la lunghezza della colonna per adattarsi alla lunghezza dei dati che si sta tentando di inserire (0000-00-00)

EDIT 1:

Seguendo il tuo commento, ho eseguito una tabella di test:

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) 

inserzione:

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

EDIT 2:

Quindi, verrà aggiustata si desidera inserire un valore NULL per pdd campo come il tuo commento Stati? Potete farlo in 2 modi come questo:

Metodo 1:

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

Metodo 2:

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

EDIT 3:

non siete riusciti a modificare l'impostazione predefinita valore del campo pdd. Ecco la sintassi come farlo (nel mio caso, ho impostato a NULL in partenza, ora voglio cambiare a 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 
2

Probabilmente si sta spingendo una stringa'NULL' al tabella, piuttosto che un effettivo NULL, ma potrebbero esserci anche altre cose, un'illustrazione:

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) 
Problemi correlati