美文网首页
可用的字段类型

可用的字段类型

作者: 三杯两盏石酒_9265 | 来源:发表于2018-12-24 18:47 被阅读7次

字段类型

数据库结构生成器包含构建表时可以指定的各种字段类型:

命令 描述
$table->bigIncrements('id'); 递增 ID(主键),相当于「UNSIGNED BIG INTEGER」
$table->bigInteger('votes'); 相当于 BIGINT
$table->binary('data'); 相当于 BLOB
$table->boolean('confirmed'); 相当于 BOOLEAN
$table->char('name', 100); 相当于带有长度的 CHAR
$table->date('created_at'); 相当于 DATE
$table->dateTime('created_at'); 相当于 DATETIME
$table->dateTimeTz('created_at'); 相当于带时区 DATETIME
$table->decimal('amount', 8, 2); 相当于带有精度与基数 DECIMAL
$table->double('amount', 8, 2); 相当于带有精度与基数 DOUBLE
$table->enum('level', ['easy', 'hard']); 相当于 ENUM
$table->float('amount', 8, 2); 相当于带有精度与基数 FLOAT
$table->geometry('positions'); 相当于 GEOMETRY
$table->geometryCollection('positions'); 相当于 GEOMETRYCOLLECTION
$table->increments('id'); 递增的 ID (主键),相当于「UNSIGNED INTEGER」
$table->integer('votes'); 相当于 INTEGER
$table->ipAddress('visitor'); 相当于 IP 地址
$table->json('options'); 相当于 JSON
$table->jsonb('options'); 相当于 JSONB
$table->lineString('positions'); 相当于 LINESTRING
$table->longText('description'); 相当于 LONGTEXT
$table->macAddress('device'); 相当于 MAC 地址
$table->mediumIncrements('id'); 递增 ID (主键) ,相当于「UNSIGNED MEDIUM INTEGER」
$table->mediumInteger('votes'); 相当于 MEDIUMINT
$table->mediumText('description'); 相当于 MEDIUMTEXT
$table->morphs('taggable'); 相当于加入递增的 taggable_id 与字符串 taggable_type
$table->multiLineString('positions'); 相当于 MULTILINESTRING
$table->multiPoint('positions'); 相当于 MULTIPOINT
$table->multiPolygon('positions'); 相当于 MULTIPOLYGON
$table->nullableMorphs('taggable'); 相当于可空版本的 morphs() 字段
$table->nullableTimestamps(); 相当于可空版本的 timestamps() 字段
$table->point('position'); 相当于 POINT
$table->polygon('positions'); 相当于 POLYGON
$table->rememberToken(); 相当于可空版本的 VARCHAR(100) 的 remember_token 字段
$table->smallIncrements('id'); 递增 ID (主键) ,相当于「UNSIGNED SMALL INTEGER」
$table->smallInteger('votes'); 相当于 SMALLINT
$table->softDeletes(); 相当于为软删除添加一个可空的 deleted_at 字段
$table->softDeletesTz(); 相当于为软删除添加一个可空的 带时区的 deleted_at 字段
$table->string('name', 100); 相当于带长度的 VARCHAR
$table->text('description'); 相当于 TEXT
$table->time('sunrise'); 相当于 TIME
$table->timeTz('sunrise'); 相当于带时区的 TIME
$table->timestamp('added_on'); 相当于 TIMESTAMP
$table->timestampTz('added_on'); 相当于带时区的 TIMESTAMP
$table->timestamps(); 相当于可空的 created_atupdated_at TIMESTAMP
$table->timestampsTz(); 相当于可空且带时区的 created_atupdated_atTIMESTAMP
$table->tinyIncrements('id'); 相当于自动递增 UNSIGNED TINYINT
$table->tinyInteger('votes'); 相当于 TINYINT
$table->unsignedBigInteger('votes'); 相当于 Unsigned BIGINT
$table->unsignedDecimal('amount', 8, 2); 相当于带有精度和基数的 UNSIGNED DECIMAL
$table->unsignedInteger('votes'); 相当于 Unsigned INT
$table->unsignedMediumInteger('votes'); 相当于 Unsigned MEDIUMINT
$table->unsignedSmallInteger('votes'); 相当于 Unsigned SMALLINT
$table->unsignedTinyInteger('votes'); 相当于 Unsigned TINYINT
$table->uuid('id'); 相当于 UUID
$table->year('birth_year'); 相当于 YEAR

字段修饰

Modifier Description
->after('column') 将此字段放置在其它字段 "之后" (MySQL)
->autoIncrement() 将 INTEGER 类型的字段设置为自动递增的主键
->charset('utf8') 指定一个字符集 (MySQL)
->collation('utf8_unicode_ci') 指定列的排序规则 (MySQL/SQL Server)
->comment('my comment') 为字段增加注释 (MySQL)
->default($value) 为字段指定 "默认" 值
->first() 将此字段放置在数据表的 "首位" (MySQL)
->nullable($value = true) 此字段允许写入 NULL 值(默认情况下)
->storedAs($expression) 创建一个存储生成的字段 (MySQL)
->unsigned() 设置 INTEGER 类型的字段为 UNSIGNED (MySQL)
->useCurrent() 将 TIMESTAMP 类型的字段设置为使用 CURRENT_TIMESTAMP 作为默认值
->virtualAs($expression) 创建一个虚拟生成的字段 (MySQL)

可用的命令别名

Command Description
$table->dropRememberToken() 删除 remember_token 字段。
$table->dropSoftDeletes() 删除 deleted_at 字段。
$table->dropSoftDeletesTz() dropSoftDeletes() 方法的别名。
$table->dropTimestamps() 删除 created_at and updated_at 字段。
$table->dropTimestampsTz() dropTimestamps() 方法的别名。

相关文章

  • 可用的字段类型

    字段类型 数据库结构生成器包含构建表时可以指定的各种字段类型: 字段修饰 可用的命令别名

  • Model field reference - Field op

    Field options (字段选项。以下参数可用于所有字段类型。所有都是可选的。) Field.null 如果...

  • Go数据-结构体(五)

    结构体 结构体(struct)将多个不同类型命名字段(field)序列打包成一个复合类型。 字段名必须唯一 可用“...

  • ElasticSearch字符串数据类型

    字符串数据类型的字段可以接受的参数 地理数据类型地理点数据类型字段接受经纬度对,可用于:1、查找一定范围内的地理点...

  • MySQL千万级表优化

    一,数据库设计优化 1)表字段名取名是小且有意义 2)选择合适的字段类型,如性别可用enum 3)字段默认不...

  • Java 之路 (十六) -- 泛型下(通配符、类型擦除、泛型的

    7. 通配符 通配符,即 "?",用来表示未知类型。 通配符可用作各种情况:作为参数,字段或局部变量的类型;有时也...

  • input之hidden

    input的hidden类型,即隐藏域,可用于一些不希望用户看到,但需要传到后台的字段。

  • Django 模型层 orm 单表操作

    一、ORM用法 1.字段类型: 属性名 = models.字段类型(定义属性时需要指定字段类型, 通过字段类型的参...

  • sqlite常用语句总结

    //创建表格 create table 表名(字段名1 字段类型1,字段名2,字段类型2,字段名3 字段类型3,....

  • 数据库表的基本的操作DDL

    新建一张表 create table 表名称( 字段1 字段的类型, 字段2 字段的类型, ...

网友评论

      本文标题:可用的字段类型

      本文链接:https://www.haomeiwen.com/subject/dxizkqtx.html