Laravel学习-迁移文件-表字段

$table->tinyIncrements('id');	     相当于自动递增 UNSIGNED TINYINT

$table->increments('id');	         递增 ID(主键),相当于 UNSIGNED INTEGER

$table->string('name', 100);	     相当于指定长度的 VARCHAR

$table->text('description');	     相当于 TEXT

$table->time('sunrise', 0);	         相当于指定位数的 TIME

$table->id();	                     $table->bigIncrements('id') 的别名

$table->foreignId('user_id');	     $table->unsignedBigInteger('user_id') 的别名

$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->tinyInteger('votes');	     相当于 TINYINT

$table->dateTime('created_at', 0);	 相当于 DATETIME ,可以指定位数

$table->dateTimeTz('created_at', 0); 相当于 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->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 MEDIUMINT

$table->mediumInteger('votes');	     相当于 MEDIUMINT

$table->mediumText('description');	 相当于 MEDIUMTEXT

$table->morphs('taggable');	         相当于加入递增 UNSIGNED BIGINT 类型的 taggable_id 与字符串类型的 taggable_type

$table->uuidMorphs('taggable');	     相当于添加一个 CHAR (36) 类型的 taggable_id 字段和
 VARCHAR (255) UUID 类型的 taggable_type

$table->multiLineString('positions'); 相当于 MULTILINESTRING

$table->multiPoint('positions');	 相当于 MULTIPOINT

$table->multiPolygon('positions');	 相当于 MULTIPOLYGON

$table->nullableMorphs('taggable');	 添加一个可以为空版本的 morphs() 字段.

$table->nullableUuidMorphs('taggable');	添加一个可以为空版本的 uuidMorphs() 字段

$table->nullableTimestamps(0);	     timestamps() 方法的别名

$table->point('position');	         相当于 POINT

$table->polygon('positions');	     相当于 POLYGON

$table->rememberToken();	         添加一个允许空值的 VARCHAR (100) 类型的 remember_token 字段
$table->set('flavors', ['strawberry', 'vanilla']);	相当于 SET

$table->smallIncrements('id');	     递增 ID(主键),相当于 UNSIGNED SMALLINT

$table->smallInteger('votes');	     相当于 SMALLINT

$table->softDeletes('deleted_at', 0);	相当于为软删除添加一个可空的 deleted_at 字段

$table->softDeletesTz('deleted_at', 0);	相当于为软删除添加一个可空的 带时区的 deleted_at 字段

$table->timeTz('sunrise', 0);	     相当于指定位数带时区的 TIME

$table->timestamp('added_on', 0);	 相当于指定位数的 TIMESTAMP

$table->timestampTz('added_on', 0);	 相当于指定位数带时区的 TIMESTAMP

$table->timestamps(0);	         相当于添加可空的 TIMESTAMP 类型的 created_at 和 updated_at

$table->timestampsTz(0);	         相当于添加指定时区的可空的 TIMESTAMP 类型的 created_at 和 updated_at


$table->unsignedBigInteger('votes'); 相当于 UNSIGNED BIGINT

$table->unsignedDecimal('amount', 8, 2);	相当于 UNSIGNED DECIMAL ,可以指定总位数和小数位数

$table->unsignedInteger('votes');	 相当于 UNSIGNED INTEGER

$table->unsignedMediumInteger('votes');	相当于 UNSIGNED MEDIUMINT

$table->unsignedSmallInteger('votes');	相当于 UNSIGNED SMALLINT

$table->unsignedTinyInteger('votes');	相当于 UNSIGNED TINYINT

$table->uuid('id');	                 相当于 UUID

$table->year('birth_year');	         相当于 YEAR

索引

创建索引

结构生成器支持多种类型的索引。

新建了一个值唯一的 email 字段,可以将 unique 方法链式地添加到字段定义上来创建索引:

$table->string('email')->unique();

二. 修改迁移文件字段

1. 首先需要下载依赖

composer require doctrine/dbal

2. 修改原有字段属性 : 

$table->string('name', 50)->change();

3. 修改字段名:

$table->renameColumn('from', 'to');//from字段改名为to字段

4. 删除字段

$table->dropColumn('votes');//删除users表的votes字段

 $table->dropColumn(['votes', 'avatar', 'location']);//删除users表里面的votes,avatar,location这三个字段

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值