“SQLSTATE [HY000]: Error general: 1215 no puede agregar restricción de clave extranjera” Código de respuesta

SQLSTATE [HY000]: Error general: 1215 no puede agregar restricción de clave extranjera

Add it in two steps, and it's good to make it unsigned too:

public function up()
{
    Schema::create('priorities', function($table) {
        $table->increments('id', true);
        $table->integer('user_id')->unsigned();
        $table->string('priority_name');
        $table->smallInteger('rank');
        $table->text('class');
        $table->timestamps('timecreated');
    });

   Schema::table('priorities', function($table) {
       $table->foreign('user_id')->references('id')->on('users');
   });

}
Lokesh003

El código de error 1215 no puede agregar restricción de clave extranjera

Try this if are data in one or more tables from foreign key references
set foreign_key_checks=0;

Else it is a problem in forign key parameters (references parameters)
Wizard Nook

Respuestas similares a “SQLSTATE [HY000]: Error general: 1215 no puede agregar restricción de clave extranjera”

Preguntas similares a “SQLSTATE [HY000]: Error general: 1215 no puede agregar restricción de clave extranjera”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código