Mysql inserts different value in reference column passed in query

Asked

Viewed 25 times

-2

Hello, when I run a insert in any table that has the users_id column that references the table glpi_users, any value greater than 126 the seat inserts the value 127, for example:

INSERT INTO `glpi_plugin_actualtime_tasks` (`tasks_id`, `actual_begin`, `users_id`)
  VALUES ('8926', '2019-06-27 19:25:22', '373');

The value that is inserted is 127 and not 373, I have no idea what it is!

Servidor: Localhost via UNIX socket
Tipo de servidor: MariaDB
Versão do servidor: 10.1.40-MariaDB - MariaDB Server
Versão do protocolo: 10

2 answers

2


The type of data TINYINT occupies a single byte and thus can represent integer values from -128 to 127. It is impossible to store the entire 373 in one TINYINT.

  • That’s right! It worked! Thank you so much for your help!

0

The users_id field should be as INTEGER NUMBER with auto increment. This way, it will always use the next number in new records.

  • Actually the users_id column is not like auto increment it is like tinyint not null, it is only a column for referencing id of table glpi_users which is auto increment of type int.

  • CREATE TABLE atak_glpi.glpi_plugin_actualtime_tasks (
 id INT(1) NOT NULL AUTO_INCREMENT,
 tasks_id INT(11) NOT NULL,
 actual_begin DATETIME DEFAULT NULL,
 actual_end DATETIME DEFAULT NULL,
 users_id TINYINT(11) NOT NULL,
 actual_actiontime INT(11) NOT NULL DEFAULT 0,
 PRIMARY KEY (id)
)
ENGINE = INNODB,
AUTO_INCREMENT = 53,
AVG_ROW_LENGTH = 334,
CHARACTER SET utf8,
COLLATE utf8_unicode_ci;

ALTER TABLE atak_glpi.glpi_plugin_actualtime_tasks 
 ADD INDEX tasks_id(tasks_id); ALTER TABLE atak_glpi.glpi_plugin_actualtime_tasks ADD INDEX users_id(users_id);

Browser other questions tagged

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