我刚开始使用 Codeigniter 3,我知道它已经过时了,但任务已设置为可以使用它。而我马上就遇到了问题,在网上翻来覆去,没有找到答案。
在我看来,我只是遗漏了一个小细节。请帮助指导我走上真正的道路。
迁移 :
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');
}
迁移.php public function index()
{
$this->load->library('migration');
if (!$this->migration->version(1))
{
show_error($this->migration->error_string());
}
}
迁移.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/';
我的错误:最佳答案
为了解决这个问题,我们必须更深入地了解名为“CI_Migration”的父类。
我有 php8.0,它在默认的 Codeigniter 3.2.0-dev 设置中运行不正确,正好是这一行:
elseif ( ! is_callable(array($class, $method)))
在文件系统/库/Migration.php但是在 3.1.0 版本中,这一行看起来像这样。
elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class))))
正是这个选项奏效了。
关于php - 迁移 Codeigniter 3 中的 "up"方法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65405139/