0

I migrate from PHP 7.4 to PHP 8.1 and now I have problem just with a table. Database: 10.3.38-MariaDB Yii version: "yiisoft/yii2": "~2.0.47",

This table structure is this:

CREATE TABLE `registro_actividad` (
  `id` int(11) NOT NULL,
  `usuario_id` int(11) DEFAULT NULL,
  `ip` varchar(20) DEFAULT NULL,
  `fecha_hora` datetime DEFAULT NULL,
  `modulo` varchar(50) DEFAULT NULL,
  `accion` varchar(20) DEFAULT NULL,
  `nivel` varchar(10) DEFAULT NULL,
  `datos` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

ALTER TABLE `registro_actividad`
  ADD PRIMARY KEY (`id`),
  ADD KEY `registro_actividad_FK` (`usuario_id`);

ALTER TABLE `registro_actividad`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;


ALTER TABLE `registro_actividad`
  ADD CONSTRAINT `registro_actividad_FK` FOREIGN KEY (`usuario_id`) REFERENCES `usuario` (`id`);

The codo from controller is:

    $registro = new RegistroActividad();
    $registro->usuario_id =7;
    $registro->ip = "127.0.1.1";
    $registro->fecha_hora = "2023-02-13 17:35:53";
    $registro->modulo = "ticket";
    $registro->accion = "update";
    $registro->datos = "hi";
    $registro->nivel ="info";
    
    if($registro->save()) {
       echo "<br>Recorded successfully";
   }else{
        echo "<br>Error to save model: <br>";
        var_dump( $registro->getErrors()  );
       
    }

When I execute just a get a void array.

Benjamin
  • 144
  • 12
  • Your `id` column is defined as `NOT NULL`, it doesn't have `AUTO INCREMENT` but you are not setting value for `id` property of your model before saving it. – Michal Hynčica Feb 14 '23 at 12:13
  • @MichalHynčica I forgot to add it on the question, but it already has auto increment. Thanks – Benjamin Feb 14 '23 at 17:43
  • Do you have any code in `beforeSave` callback or on `beforeInsert` event? Returning `false` from `save()` when there is no error might be caused by `beforeSave()` method not returning `true`. – Michal Hynčica Feb 14 '23 at 22:13

1 Answers1

0

There was a error on vendor, I just delete /vendor folder and execute "composer update" and it were resolved.

I'm not sure if exists some strage issue to migrate from php 7.4 to 8.1 on vendor but It worked for me.

Benjamin
  • 144
  • 12