1

我需要使用 codeigniter 为我的代码库中的模型创建表,

有没有办法将这些东西导出到codeignitor?

我有代码库,但我没有数据转储,所以我需要找到一种方法来做类似 Rails 迁移之类的事情

4

1 回答 1

5

使用 CodeIgniter 的 Migration 和 DBForge 类

迁移

https://www.codeigniter.com/user_guide/libraries/migration.html

DBForge 数据库操作

https://www.codeigniter.com/user_guide/database/forge.html

直接来自迁移的用户指南:

defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Add_blog extends CI_Migration {

public function up()
{
    $this->dbforge->add_field(array(
        'blog_id' => array(
            'type' => 'INT',
            'constraint' => 5,
            'unsigned' => TRUE,
            'auto_increment' => TRUE
        ),
        'blog_title' => array(
            'type' => 'VARCHAR',
            'constraint' => '100',
        ),
        'blog_description' => array(
            'type' => 'TEXT',
            'null' => TRUE,
        ),
    ));
    
    $this->dbforge->create_table('blog');
}

public function down()
{
    $this->dbforge->drop_table('blog');
}
于 2012-05-10T15:20:35.437 回答