No working "up" method in migrate Codeigniter 3 with PHP8
Asked Answered
G

1

7

I just started working with CodeIgniter 3, I understand that it is already outdated, but the task is set to work with it. And I immediately had a problem, rummaged through the Internet and did not find an answer.

It seems to me that I am just missing a small detail. Please help guide me on the true path.

Migration:

class Migration_Add_blog extends CI_Migration {

    public function up()
    {
        $this->dbforge->add_field(array(
            'id' => array(
                'type' => 'INT',
                'unsigned' => TRUE,
                'auto_increment' => TRUE
            ),
            'title' => array(
                'type' => 'TEXT',
                'null' => TRUE,
            ),
       ));
        $this->dbforge->add_key('id', TRUE);
        $this->dbforge->create_table('blog');
   }

Migrate.php

public function index()
    {
        $this->load->library('migration');

        if (!$this->migration->version(1))
        {
            show_error($this->migration->error_string());
        }
    }

migration.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');


$config['migration_enabled'] = TRUE;

$config['migration_type'] = 'sequential';

$config['migration_table'] = 'migrations';


$config['migration_auto_latest'] = FALSE;

$config['migration_version'] = 1;


$config['migration_path'] = APPPATH.'migrations/';

My Error:

The migration class "Migration_Add_blog" is missing an "up" method.

enter image description here

Galloot answered 22/12, 2020 at 8:8 Comment(1)
Your code seems correct. I would look into the current migration number and change if ($this->migration->current() === FALSE){ show_error($this->migration->error_string()); } not the version one, maybe the migration is past 1Paranoia
G
14

To solve this problem, we had to go a little deeper into the parent class called 'CI_Migration'. I have php8.0, it worked incorrectly with the default Codeigniter 3.2.0-dev setting exactly the line:

elseif ( ! is_callable(array($class, $method)))

in file system/libraries/Migration.php

But in version 3.1.0 this line looks like this.

elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class))))

And it was this option that worked.

Galloot answered 22/12, 2020 at 10:29 Comment(2)
so the php 8 was a condition :)Paranoia
Does the same error also happens for PHP 7?Rounds

© 2022 - 2024 — McMap. All rights reserved.