迁移 Codeigniter
Migrations Codeigniter
如“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;
值仍然没有结果。
只需执行以下操作:
从 application/config.php
中删除 $config['migration_enabled']=true;
并从 application/migration.php
中删除它
同时将 $config['migration_type']
从 timestamp
更改为 sequential
,将 $config['migration_version']
设置为 '001'
,同时将 $config['migration_auto_latest']
从 application/migration.php
也是。
注意:
当使用 enviromental/fastcgi 参数时,使用 env
UNIX 命令以通过 cli 执行 php。
如“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;
值仍然没有结果。
只需执行以下操作:
从 application/config.php
中删除 $config['migration_enabled']=true;
并从 application/migration.php
同时将 $config['migration_type']
从 timestamp
更改为 sequential
,将 $config['migration_version']
设置为 '001'
,同时将 $config['migration_auto_latest']
从 application/migration.php
也是。
注意:
当使用 enviromental/fastcgi 参数时,使用 env
UNIX 命令以通过 cli 执行 php。