【发布时间】:2017-01-11 21:10:59
【问题描述】:
我正在使用 Laravel 的默认迁移来创建通知表。
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
但我在尝试使用时遇到错误:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `notifications` add index `n
otifications_notifiable_id_notifiable_type_index`(`notifiable_id`, `notifiable_type`))
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
更新
我将索引列的名称更改为notifiable_index,但它仍然抱怨索引键的长度。
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `notifications` add index `n
otifiable_index`(`notifiable_id`, `notifiable_type`))
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
【问题讨论】:
-
notifiable列的排序规则是什么? -
你解决了吗?
-
@PhilippSander 不得不使用另一种方法来创建更短的密钥。