1265: Data truncated for column 'envio' at row 1 - mysql

I'm with a problem in following insert SQL below:
insert into cad_manutencao (id,
causa_provavel,
envio,
retorno,
nota_envio,
rastreamento,
transportadora,
chegou)
values (1,
'TESTANDO ASSISTENCIA',
'12/02/2015 15:00:00',
'12/02/2015 15:00:00',
'S/NF',
'AssistĂȘncia',
1,
1)
When i run this SQL the MySQL return this warning:
"1265: Data truncated for column 'envio' at row 1"
This SQL works and the register is added, but the date fields are filled as NULL
How can i solve this problem?
Thanks a lot!

This is not a valid format for a date in mysql. You have to change the query like this :
insert into cad_manutencao (id,
causa_provavel,
envio,
retorno,
nota_envio,
rastreamento,
transportadora,
chegou)
values (1,
'TESTANDO ASSISTENCIA',
'2015-02-12 15:00:00',
'2015-02-12 15:00:00',
'S/NF',
'AssistĂȘncia',
Date format for mysql is yyyy-mm-dd.

Related

Single column (with spaces) name gets split into two

I am using codeigniter insert_batch($table, $data);
I have a column name as "Comment posted by the customer".
When I try to batch insert data into it. The insert query changes as:
INSERT INTO `table` (`id`, `Name`, `Status`,`Comment posted by the` `customer`, `isActive`) VALUES (),(),()...;
As seen the column splits up into 2 parts -
1.Comment posted by the
2.customer
And this throws an error. How do I overcome this? I need to insert it considering it as a single column.
Try to format the query like this
INSERT INTO table (id, Name, Status, `Comment posted by the customer`, isActive) VALUES (),(),()
UPDATE
You can omit the column names and specify the values for all columns
INSERT INTO table VALUES (), (), ()

Column count doesn't match value count in MySQL

Whenever I am trying to insert data in table:
INSERT INTO `operator`(`id`, `operator_name`, `email`, `info`)
VALUES (1,'Bangalink','This is all about Banglalink'),
(2, 'Robi', 'This is all about Robi');
MySQL said:#1136 - Column count doesn't match value count at row 1
How can i fix it?
I don't understand what need to do.
TIA
The provided number of columns in the column list specification and number of column values in each record must match.
Assuming you don't want to insert email data, remove that from the column list:
INSERT INTO `operator`(`id`, `operator_name`, `info`)
VALUES (1,'Bangalink','This is all about Banglalink'),
(2, 'Robi', 'This is all about Robi');
or pass null for email:
INSERT INTO `operator`(`id`, `operator_name`, `email`, `info`)
VALUES (1,'Bangalink',null,'This is all about Banglalink'),
(2, 'Robi', null,'This is all about Robi');
Second method is useful when you may have emails for few records.
You pass one item - info:
INSERT INTO `operator`(`id`, `operator_name`, `email`, `info`)
VALUES (1,'Bangalink','This is all about Banglalink', NULL),
(2, 'Robi', 'This is all about Robi',NULL);
or
INSERT INTO `operator`(`id`, `operator_name`, `email`)
VALUES (1,'Bangalink','This is all about Banglalink'),
(2, 'Robi', 'This is all about Robi');

How ignore error when the data is replaced in mySQL?

I insert data into the table as follows:
REPLACE INTO `test`(`id`,`text`) VALUES (1,'first'), (2, 'second'), (3, 'third')
But if one of the sets of data is incorrect, then all the other sets do not fall into the table.
REPLACE INTO `test`(`id`,`text`) VALUES (1,'new first'), (2, NULL), (3, 'new third')
How to achieve the following:
The first and third set of data is to replace the existing data in the table. And the second is to be ignored, and the data in the table should not change.
Try
insert ignore INTO `test`(`id`,`text`) VALUES (1,'new first'), (2, NULL), (3, 'new third')
insert ignore command work as replace command but it convert errors into warning.

"decimal" - Data truncated for column

I'm trying to add some test values into my database, but I'm always getting this Data truncated for column ... error when I enter decimal values.
For example I'm trying to enter this:
INSERT INTO `offers` (`id`, `userid`, `amount`, `onebtc`, `price`, `discount`) VALUES (NULL, '6', '14,22', '0', '10,32', '1');
into this table:
table
Have you tried to sending a decimal instead of a string??
INSERT INTO offers (id, userid, amount, onebtc, price, discount) VALUES (NULL, 6, 14.22, 0, 10.32, 1);
You're sending strings for everthing, so MySQL has to type cast it for you.

MySQL Unknown column in field list.. occurs with uppercase columns only

This works:
INSERT INTO people (`name`, `job`) values ('Bob', 'sales')
but this fails:
INSERT INTO people (`name`, `Sold`) values ('Bob', '56')
Giving the error:
Unknown column 'Sold' in 'field list'
All fields are of type varchar. Can't figure this out!
This error is referring to the table column name Sold in the table people.
Your two examples are meaningless because you didn't successfully insert a value into the column Sold in the first example. Neither did you successfully insert a number into a VARCHAR column in the first example.
This has nothing to do with a type mismatch, the error says this column is unknown (doesn't exist).
Try this:
INSERT INTO people (name, sold) values ('Bob', '56')
I'll need more informations about table
INSERT INTO test (`name`, `Sold`) values ('Bob', '56')
worked for me given that the table was created like this..
create table test (id int, name varchar(6),Sold varchar(4),job varchar(7));
please check your data type in the created 'Sold' column.
it could be a boolean in your case..