# CodeIgniter 迁移类 - 创建一个迁移信息

**URL:** <https://www.isharkfly.com/t/codeigniter/5166>\
**Category:** PHP\
**Created:** [January 8, 2014, 4:34am UTC](https://www.isharkfly.com/t/codeigniter/5166 "2014-01-08T04:34:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 8, 2014, 4:34am UTC](https://www.isharkfly.com/t/codeigniter/5166/1 "2014-01-08T04:34:29Z")

</div>

这将是一个 blog 站点的第一个迁移信息。所有的迁移信息都在文件夹 application/migrations/ 里，并且具有这样的名称，例如：001\_add\_blog.php.[code]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’);  
}[/code]然后在文件 application/config/migration.php 中设置 $config[‘migration\_version’] = 1;。

文章来源：[http://cwiki.ossez.com/pages/viewpage.action?pageId=2392165](http://cwiki.ossez.com/pages/viewpage.action?pageId=2392165)
