温馨提示:本文共901个字,读完预计3分钟。
建表步骤:
1、进入容器
docker exec -it crm /bin/bash
2、建migrate文件
php yii migrate/create create_modules 并写好字段
3、注册到库中
php yii migrate
4、执行gii 生成model文件
域名/gii
5、SeedController中书写填充数据
/**
* 行业数据填充
* @return bool
* @throws Exception
*/
public function actionIndustry()
{
$delete_num = Industry::deleteAll();
echo 'delete ' . $delete_num . ' industry' . PHP_EOL;
$created_by = $this->admin()->getId();
$columns = [‘name’, ‘created_by’, ‘created_at’, ‘updated_at’];
$now = time();
$data = [
[‘直播’, $created_by, $now, $now],
[‘物流’, $created_by, $now, $now],
[‘游戏’, $created_by, $now, $now],
[‘金融’, $created_by, $now, $now],
[‘电商’, $created_by, $now, $now],
];
$query = Industry::find()->createCommand()->batchInsert(Industry::tableName(), $columns, $data);
echo $query->getRawSql() . PHP_EOL;
$query->query();
echo 'industry seed success' . PHP_EOL;
return true;
}
6、执行填充命令
php yii seed/industry