在准备迁移时,尝试检查表上是否存在唯一索引,如何实现?
Schema::table('persons',function (Blueprint $table) {
if ($table->hasIndex('persons_body_unique')) {
$table->dropUnique('persons_body_unique');
}
})
看起来像上面的东西. (显然,hasIndex()不存在)
最佳答案
使用Laravel使用的“doctrine-dbal”是更好的解决方案:
Schema::table('persons',function (Blueprint $table) {
$sm = Schema::getConnection()->getDoctrineSchemaManager();
$indexesFound = $sm->listTableIndexes('persons');
if(array_key_exists("persons_body_unique",$indexesFound))
$table->dropUnique("persons_body_unique");
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。