周大胖子 发表于 2019-7-5 11:19:11

Laravel 中 数据迁移的 一个实例 【 空不 空的、索引都在这】

// 新建数据表 [ 不规定数据长度 无法创建索引 ]
      Schema::create('xlist'.$count, function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->tinyInteger('ctype')->comment('国际分类')->index();
            $table->char('mtype', 4)->comment('近似群')->index();
            $table->string('xtype',11)->comment('小分类')->index();
            $table->string('spfw', 60)->comment('商品服务名称')->index();
            $table->string('datatype',11)->comment('尼斯分类')->index()->nullable();
            $table->char('wu', 1)->comment('五方');
            $table->tinyInteger('t')->default(1)->comment('主要是用来判断是否更新')->index();
            $table->index(['mtype', 'xtype']);
      });1.其中 不规定长度就创建索引,凉凉
2.设置空的问题 是在后面接 ->nullable() 这样这个字段就允许为空,否则默认不允许为空 ;

参考文献:https://www.jason-z.com/post/laravel-change-column-not-nullable-in-migration 【这个地址主要讲空不空的设置】

页: [1]
查看完整版本: Laravel 中 数据迁移的 一个实例 【 空不 空的、索引都在这】