gpt4 book ai didi

mysql - Laravel 创建表错误

转载 作者:行者123 更新时间:2023-11-29 01:53:03 25 4
gpt4 key购买 nike

vagrant@homestead:~/www/laravel$ php artisan migrate

当我运行代码时没有创建最新的数据库表。

工作:

  • 角色
  • 权限
  • 权限角色

错误:

  • 角色用户

enter image description here

这是我编码我的数据库迁移..

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolePermissions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('label');
$table->timestamps();

});

Schema::create('permissions', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('label');
$table->timestamps();

});

Schema::create('permission_role', function(Blueprint $table){
$table->integer('role_id')->unsigined();
$table->integer('permission_id')->unsigined();

$table->foreign('role_id')
->referance('id')
->on('roles')
->onDelete('cascade');

$table->foreign('permission_id')
->referance('id')
->on('permissions')
->onDelete('cascade');

$table->primary(['role_id', 'permission_id']);

});

Schema::create('role_user', function(Blueprint $table){
$table->integer('role_id')->unsigined();
$table->integer('user_id')->unsigined();

$table->foreign('role_id')
->referance('id')
->on('roles')
->onDelete('cascade');

$table->foreign('user_id')
->referance('id')
->on('users')
->onDelete('cascade');

$table->primary(['role_id', 'user_id']);

});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\DB::statement('SET FOREIGN_KEY_CHECKS = 0');

Schema::drop('roles');
Schema::drop('permissions');
Schema::drop('permission_role');
Schema::drop('role_user');

\DB::statement('SET FOREIGN_KEY_CHECKS = 1');

}
}

如果你帮我解决这个问题我会很高兴很长一段时间。

谢谢。

最佳答案

应该是->references(),不是->referance()

https://laravel.com/docs/5.1/migrations#foreign-key-constraints

关于mysql - Laravel 创建表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36250196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com