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.
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.