Laravel Schema has a command for ENUM equivalent to the table. What is the SET equivalent to the table?
5条回答 默认 最新
- dqhdpppm02183 2014-06-19 07:18关注
As of now Laravel Schema Builder does not support SET datatype for columns. So, here is an alternative solution until someone add those code to Laravel.
Step 1: Create the table, use ENUM instead of SET.
Schema::create('schools', function($table) { $table->increments('id'); $table->char('id_number', 6); $table->string('school_name'); $table->enum('level', array('Preschool', 'Kindergarten', 'Primary', 'Secondary'))->index(); // *** fix this $table->string('phone'); $table->string('email'); $table->string('location'); $table->smallInteger('city')->unsigned()->index(); $table->smallInteger('country')->unsigned()->index(); $table->smallInteger('head_teacher')->unsigned()->index(); $table->smallInteger('director')->unsigned()->index(); $table->smallInteger('created_by')->unsigned(); $table->smallInteger('modified_by')->unsigned(); $table->timestamps(); });
Step 2: Now change ENUM to SET.
$table_prefix = DB::getTablePrefix(); DB::statement("ALTER TABLE `" . $table_prefix . "schools` CHANGE `level` `level` SET('Preschool','Kindergarten','Primary','Secondary');");
If you have a better solution, then please let me know.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀
- ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
- ¥15 关于#hadoop#的问题
- ¥15 (标签-Python|关键词-socket)
- ¥15 keil里为什么main.c定义的函数在it.c调用不了
- ¥50 切换TabTip键盘的输入法
- ¥15 可否在不同线程中调用封装数据库操作的类
- ¥15 微带串馈天线阵列每个阵元宽度计算
- ¥15 keil的map文件中Image component sizes各项意思