【发布时间】:2017-04-03 19:30:28
【问题描述】:
如“How do I run CodeIgniter migrations?”上所示,我创建了以下迁移控制器:
class Migrate extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->input->is_cli_request()
or exit("Execute via command line: php index.php migrate");
$this->load->library('migration');
}
public function index()
{
if(!$this->migration->latest())
{
show_error($this->migration->error_string());
}
}
}
以及migrations/001_CreateUserTable下的如下迁移脚本:
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_CreateUserTable extends CI_Migration
{
private $table='user';
public function up()
{
$this->dbforge->add_field('id INT UNSIGNED NOT NULL AUTO INCREMENT')
->add_field('username VARCHAR(30) NOT NULL')
->add_field('password VARCHAR(200) NOT NULL');
$this->dbforge->add_key('id',true);
$this->dbforge->create_table($this->table);
}
public function down()
{
$this->dbforge->drop_table($this->table);
}
}
但是当我在命令行界面上运行时:
php index.php migrate
我收到以下错误:
错误:遇到错误
迁移已加载,但被禁用或设置不正确。
你有什么想法可以解决吗?
编辑 1
在application/config 上我设置了$config['migration_enabled']=true; 值仍然没有结果。
【问题讨论】:
标签: codeigniter database-migration