我正在尝试迁移整个laravel应用程序,当我编写下面的代码时,出现了一些错误。
// Create table for associating permissions to users (Many To Many Polymorphic)
Schema::create('permission_user', function (Blueprint $table) {
$table->unsignedInteger('permission_id');
$table->unsignedInteger('user_id');
$table->string('user_type');
$table->unsignedInteger('project_id')->nullable();.
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('project_id')->references('id')->on('projects')
->onUpdate('cascade')->onDelete('cascade');
$table->unique(['user_id', 'permission_id', 'user_type', 'project_id']);
});
错误:
sqlstate[42000]:语法错误或访问冲突:1059标识符名称“permission\u user\u user id\u permission\u id\u user\u type\u project\u id\u unique”太长(sql:alter table) permission_user
添加唯一的 permission_user_user_id_permission_id_user_type_project_id_unique
( user_id
, permission_id
, user_type
, project_id
))`
当我删除上面的代码时,一切正常。怎么了?我什么都没找到?!
1条答案
按热度按时间isr3a4wc1#
laravel生成唯一密钥的方法太长。你可以通过
另外,如果外键太长,可以覆盖默认名称,但提供第二个参数。