2017-04-03 67 views
1

正如所看到的「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;值還是沒有結果。

回答

0

只需做到以下幾點:

刪除application/config.php$config['migration_enabled']=true;和偶然從application/migration.php

而且從timestamp改變$config['migration_type']sequential,設置$config['migration_version']'001',也改變從application/migration.php$config['migration_auto_latest']了。

注: 當使用ENVIROMENTAL/fastcgi的參數,以便通過CLI執行PHP使用env UNIX命令。