Hello! Please,i need help. I'm using laravel 6,i'am creating migrations,my question is how to correct this error.?This is the error. Really,i don't see where is the error.Urgent
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table `epacahier`.`users` (errno: 150 "Foreign key constraint is incorrectly
Look at the code:
users migration
/* Users migration*/
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Users extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->bigInteger('filiere_id'); $table->bigInteger('annee_id');
$table->string('nom');
$table->string('password');
$table->string('telephone');
$table->string('email');
$table->integer('is_deleted');
$table->string('activation_state');
$table->string('role');
$table->string('secteur');
$table->timestamps();
$table->foreign('filiere_id')->references('id')->on('filiere')->onDelete('cascade'); $table->foreign('annee_id')->references('id')->on('annee')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
filiere migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Annee extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('annee', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('debut');
$table->integer('fin');
$table->boolean('actif');
$table->boolean('close');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('annee');
}
}
annee migration
<?php
/* filiere migration*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Filiere extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('filiere', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->bigInteger('departement_id')->unsigned();
$table->string('nom');
$table->timestamps();
$table->foreign('departement_id')->references('id')->on('departement')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('filiere');
}
}
migration
Laravel 6:Migrations
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.