У меня есть таблица "пользователи".Некоторые пользователи связаны с другими пользователями через поле "consultant_id".
Когда я создаю свою базу данных с php artisan migrate
, я получаю сообщение об ошибке PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('first_name', 255);
$table->string('last_name', 255);
$table->string('email', 255)->unique();
$table->string('password');
$table->integer('consultant_id')->unsigned()->nullable()->index();
$table->integer('profile_id')->unsigned()->nullable();
$table->rememberToken();
$table->timestamps();
});
Schema::table('users', function(Blueprint $table) {
$table->foreign('consultant_id')->references('id')->on('users')
->onDelete('set null')
->onUpdate('cascade');
});
Canты поможешь мне ?
Большое спасибо!