I have a table "users". Some users are linked to other users via the "consultant_id" field.
When I create my database with php artisan migrate
, I receive an error 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 you help me ?
Thank you very much!