Laravel Schema中的MySQL数据类型SET是什么? [英] What is the MySQL datatype SET equivalent in Laravel Schema?

查看:561
本文介绍了Laravel Schema中的MySQL数据类型SET是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Laravel Schema 有一个ENUM命令,相当于表格。什么是SET等同于表?

Laravel Schema has a command for ENUM equivalent to the table. What is the SET equivalent to the table?

推荐答案

现在Laravel Schema Builder不支持列的SET数据类型。所以,这里是一个替代解决方案,直到有人将这些代码添加到Laravel。

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.

步骤1:创建表,使用ENUM而不是SET。

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();
});

现在将ENUM更改为SET。

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.

这篇关于Laravel Schema中的MySQL数据类型SET是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆