我知道如何通过qazxswpoi创建它们
但是,一旦我创建了我的迁移文件,我该如何运行它们?
我不确定这是正确的做法,但它对我有用。
我创建了一个名为http://codeigniter.com/user_guide/libraries/migration.html的控制器(controllers / migrate.php)。
migrate
然后从浏览器我将调用此url在<?php defined("BASEPATH") or exit("No direct script access allowed");
class Migrate extends CI_Controller{
public function index($version){
$this->load->library("migration");
if(!$this->migration->version($version)){
show_error($this->migration->error_string());
}
}
}
控制器中执行index
操作
例如:http://localhost/index.php/migrate/index/1
使用这些页面作为参考:migrate
和Running via the CLI,您可以将对迁移控制器的访问权限限制为命令行(application / controllers / migrate.php):
Migration Class
然后执行最新的迁移,进入项目目录的根目录并运行:
<?php if ( ! defined('BASEPATH')) exit("No direct script access allowed");
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());
}
}
}
但是当您尝试通过webserver domain.com/migrate访问时,您将在上面的脚本中看到该文本。
您还可以为向下或向上迁移运行某个版本:
php index.php migrate
对于CLI,运行此命令if(!defined('BASEPATH')) exit('No direct script access allowed');
class Migrate extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->library('migration');
}
public function version($version)
{
if($this->input->is_cli_request())
{
$migration = $this->migration->version($version);
if(!$migration)
{
echo $this->migration->error_string();
}
else
{
echo 'Migration(s) done'.PHP_EOL;
}
}
else
{
show_error('You don\'t have permission for this action');;
}
}
}
,其中php index.php migrate version 5
是迁移的版本。如果版本更多是当前迁移 - 向上迁移,否则 - 向下到输入版本。
5
试试这个,我已经为此编写了一个库,可以通过CLI轻松使用。它可用于创建迁移文件并向后或向前运行迁移。
`.
<?php defined("BASEPATH") or exit("No direct script access allowed");
class Migrate extends CI_Controller {
public function index() {
if (ENVIRONMENT == 'development') {
$this->load->library('migration');
if ( ! $this->migration->current()) {
show_error($this->migration->error_string());
} else {
echo "success";
}
} else {
echo "go away";
}
}
}
?>
。$config['migration_enabled'] = TRUE;