正如所看到的「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
我收到以下錯誤:
ERROR: An Error Was Encountered
Migrations has been loaded but is disabled or set up incorrectly.
你有什麼想法可以解決它嗎?
編輯1
在application/config
我設置了$config['migration_enabled']=true;
值還是沒有結果。