Error inserting Data into Mysql

Asked

Viewed 2,956 times

0

I have this query to insert a data into the database:

INSERT INTO `bancoTeste`.`TabelaTeste` (`t_id`,`t_label`, `t_parametro`, `t_valor`, `t_descricao`, `t_valores_padrao`, `t_tipo`) 
VALUES ('NULL','Cargas', 'monitorar_carga','N', 'apresentar as cargas dos veículos do grupo de monitoramento','sim_ou_nao', 'combo');

Mysql error

1 Row(s) affected, 1 Warning(s): 1366 Incorrect integer value: 'NULL' for column 'sis00_id' at Row 1

How to proceed ?

  • you want to enter the NULL value in the t_id ok? field if that’s better than '0' no? or the field is not INT?

2 answers

4


Remove the quotes from 'NULL', otherwise it will be a string incompatible with the column value type t_id table.

With 'NULL' (in quotes), will insert the record in the table, according to the message:

1 Row(s) affected

But it will generate the alert:

1 Warning(s)

In the form below, the alert will not be generated:

INSERT INTO `bancoTeste`.`TabelaTeste` (`t_id`,`t_label`, `t_parametro`, `t_valor`, `t_descricao`, `t_valores_padrao`, `t_tipo`) 
VALUES (NULL,'Cargas', 'monitorar_carga','N', 'apresentar as cargas dos veículos do grupo de monitoramento','sim_ou_nao', 'combo');

But if the column t_id for a while primary-key auto_increment, just omit it:

INSERT INTO `bancoTeste`.`TabelaTeste` (`t_label`, `t_parametro`, `t_valor`, `t_descricao`, `t_valores_padrao`, `t_tipo`) 
VALUES ('Cargas', 'monitorar_carga','N', 'apresentar as cargas dos veículos do grupo de monitoramento','sim_ou_nao', 'combo');

0

Just remove the t_id from sql. In your database this field is set to auto_increment? If you are just remove it. A sql would look like this:

INSERT INTO `bancoTeste`.`TabelaTeste` (`t_label`, `t_parametro`, `t_valor`, `t_descricao`, `t_valores_padrao`, `t_tipo`) VALUES ('Cargas', 'monitorar_carga','N', 'apresentar as cargas dos veículos do grupo de monitoramento','sim_ou_nao', 'combo');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.