【发布时间】:2019-05-17 04:06:06
【问题描述】:
我想创建一个多个唯一的列,但是当我运行php artisan migrate 时,我得到了这个错误:
SQLSTATE[42000]:语法错误或访问冲突:1071 指定键 太长了;最大密钥长度为 1000 字节
这是我的代码:
Schema::create('buku', function (Blueprint $table) {
$table->increments('id');
$table->string('judul');
$table->string('pengarang');
$table->string('penerbit');
$table->string('thn_terbit',4);
$table->integer('stok');
$table->string('kategori');
$table->timestamps();
$table->unique(['judul','pengarang','penerbit','thn_terbit'],'unik');
});
这个AppServiceProvider.php 文件
public function boot()
{
Schema::defaultStringLength(191);
}
我们将不胜感激
版本:Laravel 5.7
[已解决]
我通过添加$table->engine = 'innoDB'; 解决了这个问题,因此代码如下所示:
Schema::create('buku', function (Blueprint $table) {
$table->engine = 'innoDB';
$table->increments('id');
$table->string('judul');
$table->string('pengarang');
$table->string('penerbit');
$table->string('thn_terbit');
$table->integer('stok');
$table->string('kategori');
$table->timestamps();
$table->unique(['judul','pengarang','penerbit','thn_terbit'],'unik');
});
然后重新迁移它,一切都很好。
【问题讨论】:
-
请添加您的解决方案作为答案,然后自行接受。然后根据您的问题编辑您的答案。谢谢