简体   繁体   English

如何在 codeigniter 上进行迁移?

[英]How can I do a migration on codeigniter?

I'm using the migration codes which works on CodeIgniter 2 but they won't work on CodeIgniter 3我正在使用适用于 CodeIgniter 2 的迁移代码,但它们不适用于 CodeIgniter 3

I have read most of the questions here similar to my problem but I could not find an answer.我已经阅读了与我的问题类似的大部分问题,但我找不到答案。

........ …………

class Migration_Create_users extends CI_Migration
{
   public function up()
   {
       $this->dbforge->add_field([
           'id'       => [
               'type'           => 'INT',
               'constraint'     => 11,
               'unsigned'       => true,
               'auto_increment' => true,
           ],
           'email'    => [
               'type'       => 'VARCHAR',
               'constraint' => '100',
           ],
           'password' => [
               'type'       => 'VARCHAR',
               'constraint' => '128',
           ],
           'name'     => [
               'type'       => 'VARCHAR',
               'constraint' => '100',
           ],
       ]);
       $this->dbforge->add_key('id', true);
       $this->dbforge->create_table('users');
   }
   public function down()
   {
       $this->dbforge->drop_table('users');
   }
}
class Migration extends Admin_Controller
{
    public function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
        $this->load->library('migration');
        if (!$this->migration->current()) {
            show_error($this->migration->error_string());
        } else {
            echo 'Migration worked!';
        }
    }
}

//migration config //迁移配置

defined('BASEPATH') or exit('No direct script access allowed');
$config['migration_enabled']     = true;
$config['migration_type']        = 'sequential';
$config['migration_table']       = 'migrations';
$config['migration_auto_latest'] = false;
$config['migration_version']     = 001;
$config['migration_path']        = APPPATH . 'migrations/';

I expect to run the code then I get the table created in the database我希望运行代码然后我在数据库中创建表

Please do with the below function请使用以下功能

class Migrate extends CI_Controller{

    public function index($version){
        $this->load->library("migration");

      if(!$this->migration->version($version)){
          show_error($this->migration->error_string());
      }   
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM