Welcome Guest, Not a member yet? Register   Sign In
Error with allowed NULL integer field
#1

[eluser]ReyPM[/eluser]
Hi, I've this table:
Code:
CREATE TABLE IF NOT EXISTS `autores_ppi` (
  `ID_AUTOR_PPI` int(11) NOT NULL AUTO_INCREMENT,
  `ID_AUTOR` int(11) NOT NULL,
  `NIVEL_ING` varchar(3) DEFAULT NULL,
  `COHORTE` int(11) DEFAULT NULL,
  `PSEUDO_COH` int(11) DEFAULT NULL,
  `COMISION` varchar(4) DEFAULT NULL,
  `PUB_PPI` int(11) DEFAULT NULL,
  `NIVEL_EGR` varchar(3) DEFAULT NULL,
  `ANO_EGR` int(11) DEFAULT NULL,
  `ANO_REING` int(11) DEFAULT NULL,
  `ANO_LIC` int(11) DEFAULT NULL,
  `MENCIO_LIC` varchar(32) DEFAULT NULL,
  `AREA_LIC` varchar(18) DEFAULT NULL,
  `UNIVER_LIC` varchar(60) DEFAULT NULL,
  `PAIS_LIC` varchar(18) DEFAULT NULL,
  `MAX_GRADO` varchar(12) DEFAULT NULL,
  `ANO_MA_PSG` int(11) DEFAULT NULL,
  `DOCTORADO` tinyint(1) DEFAULT NULL,
  `ANO_DOC` int(11) DEFAULT NULL,
  `UNIVER_DOC` varchar(60) DEFAULT NULL,
  `PAIS_DOC` varchar(18) DEFAULT NULL,
  `COD_ESPEC` varchar(6) DEFAULT NULL,
  `ESPECIALIZ` varchar(30) DEFAULT NULL,
  `NUM_MAE` int(11) DEFAULT NULL,
  `ANO_MAE` int(11) DEFAULT NULL,
  `UNIVER_MAE` varchar(60) DEFAULT NULL,
  `PAIS_MAE` varchar(18) DEFAULT NULL,
  PRIMARY KEY (`ID_AUTOR_PPI`),
  KEY `FK_autores_ppi_1` (`ID_AUTOR`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

So I try to insert some data and this is the POST result of that data:
Code:
Array
(
    [ID_AUTOR] => 44339
    [NIVEL_ING] => 1
    [COHORTE] =>
    [PSEUDO_COH] =>
    [COMISION] =>
    [PUB_PPI] =>
    [NIVEL_EGR] =>
    [ANO_EGR] =>
    [ANO_REING] =>
    [ANO_LIC] =>
    [MENCIO_LIC] =>
    [AREA_LIC] =>
    [UNIVER_LIC] =>
    [PAIS_LIC] =>
    [MAX_GRADO] =>
    [ANO_MA_PSG] =>
    [DOCTORADO] =>
    [ANO_DOC] =>
    [UNIVER_DOC] =>
    [PAIS_DOC] =>
    [COD_ESPEC] =>
    [ESPECIALIZ] =>
    [NUM_MAE] =>
    [ANO_MAE] =>
    [UNIVER_MAE] =>
    [PAIS_MAE] =>
)
But I get this error:
Quote:Error Number: 1366

Incorrect integer value: '' for column 'COHORTE' at row 1

INSERT INTO `autores_ppi` (`ID_AUTOR`, `NIVEL_ING`, `COHORTE`, `PSEUDO_COH`, `COMISION`, `PUB_PPI`, `NIVEL_EGR`, `ANO_EGR`, `ANO_REING`, `ANO_LIC`, `MENCIO_LIC`, `AREA_LIC`, `UNIVER_LIC`, `PAIS_LIC`, `MAX_GRADO`, `ANO_MA_PSG`, `DOCTORADO`, `ANO_DOC`, `UNIVER_DOC`, `PAIS_DOC`, `COD_ESPEC`, `ESPECIALIZ`, `NUM_MAE`, `ANO_MAE`, `UNIVER_MAE`, `PAIS_MAE`) VALUES ('44339', '1', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')

Filename: /home/reynierpm/public_html/biblios/models/mauthor.php

Line Number: 180

Isn't suppose that field COHORTE allows empty or null values? What's wrong here?
#2

[eluser]vickel[/eluser]
Maybe this helps:

For data entry into a NOT NULL column that has no explicit DEFAULT clause, if an INSERT or REPLACE statement includes no value for the column, or an UPDATE statement sets the column to NULL, MySQL handles the column according to the SQL mode in effect at the time:

If strict SQL mode is enabled, an error occurs for transactional tables and the statement is rolled back. For nontransactional tables, an error occurs, but if this happens for the second or subsequent row of a multiple-row statement, the preceding rows will have been inserted.

If strict mode is not enabled, MySQL sets the column to the implicit default value for the column data type.

check: http://dev.mysql.com/doc/refman/5.0/en/d...aults.html
#3

[eluser]Narf[/eluser]
It's really simple - '' denotes an empty string and you're trying to insert that into a non-string (integer) field. Write NULL, not ''.
#4

[eluser]ReyPM[/eluser]
Thanks bot of you I don't know if I'm right but I solve just making a typecast to the empty string
Code:
(int) ""
but once again any other solution will be welcome
Regards




Theme © iAndrew 2016 - Forum software by © MyBB