Laravel 8 删除索引

2021-07-19 11:20 更新

若要删除索引,则必须指定索引的名称。Laravel 默认会自动将数据表名称、索引的字段名及索引类型简单地连接在一起作为名称。举例如下:

命令 说明
$table->dropPrimary('users_id_primary'); 从 「users」 表中删除主键
$table->dropUnique('users_email_unique'); 从 「users」 表中删除 unique 索引
$table->dropIndex('geo_state_index'); 从 「geo」 表中删除基本索引
$table->dropSpatialIndex('geo_location_spatialindex'); 从 「geo」 表中删除空间索引(不支持 SQLite)

如果将字段数组传给 dropIndex 方法,会删除根据表名、字段和键类型生成的索引名称。

Schema::table('geo', function (Blueprint $table) {
    $table->dropIndex(['state']); // 删除 'geo_state_index' 索引
}); 
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号