【问题标题】:Migrations Codeigniter迁移代码点火器
【发布时间】: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


    【解决方案1】:

    只需执行以下操作:

    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更改。

    注意: 使用环境/fastcgi 参数时,请使用env UNIX 命令以通过 cli 执行 php。

    【讨论】:

      猜你喜欢
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 2011-06-04
      • 2016-01-28
      • 2012-06-30
      • 2012-02-21
      • 2011-03-29
      相关资源
      最近更新 更多