thinkphp mysql ignore_ThinkPHP5.1 中的数据库迁移和数据填充

总结

数据库迁移类似于数据库的SVN,可方便用于团队开发工程中的系统应用数据结构初始化、新建或删除表、新增或修改表字段等操作。

Thinkphp提供了think-migration扩展用户数据库的迁移和数据填充

数据库迁移

1. 安装和创建迁移类

$ composer require topthink/think-migration=2.0.*

$ php think migrate:create Third

表名称首字母需大写,如下图:

7ef95184466a73c77d043c275d9f1bcd.png

系统会自动生成迁移类文件:

da250d82d4f0af3a0459b5d9bb640a30.png

2. 编辑操作方法

use think\migration\Migrator;

use think\migration\db\Column;

use Phinx\Db\Adapter\MysqlAdapter; //如创建MYSQL特有字段,需导入该命名空间

class Test extends Migrator

{

public function change()

{

$table = $this->table('third', ['engine' => 'InnoDB', 'collation' => 'utf8_bin', 'comment' => '测试表']);

$table->addColumn('member_id', 'integer', ['limit' => 10, 'signed' => false, 'default' => '0', 'comment' => 'MYSQL:int'])//unsigned:('signed' => false)

->addColumn('thirdid', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'signed' => false, 'default' => '0', 'comment' => 'MYSQL:tiny

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值