laravel errno 150 foreign key-Einschränkung wird falsch gebildet

Kann jemand mir helfen, dieses problem zu lösen?

Gibt es 3 Tische, mit 2 foreign keys:

         Schema::create('users', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('name');
                    $table->string('email')->unique();
                    $table->string('password');
                    $table->rememberToken();
                    $table->timestamps();
                });

        Schema::create('firms', function (Blueprint $table) {
                    $table->increments('id');
                    $table->string('title')->nullable();  
                    $table->integer('user_id')->unsigned()->nullable();
                    $table->foreign('user_id')->references('id')->on('users');
                    $table->timestamps();
                });
       Schema::create('jobs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title')->nullable();
            $table->integer('firm_id')->unsigned()->nullable();
            $table->foreign('firm_id')->references('id')->on('firms');
            $table->timestamps();
        });

Fehler nach der Ausführung der migration:

[Illuminate\Database\QueryException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
   (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter ta
  ble `firms` add constraint `firms_user_id_foreign` foreign key (`user_id`)
  references `users` (`id`))

  [PDOException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
   (errno: 150 "Foreign key constraint is incorrectly formed")
Sorry, es funktioniert nicht: Schema::create('Unternehmen', function (Blueprint $Tabelle) { $table-> - Schritten('id')->unsigned(); Schema::create('jobs', function (Blueprint $Tabelle) { $table-> - Schritten('id'); $Tabelle->Ganzzahl('firm_id')->unsigned(); $Tabelle->Fremdsprachen('firm_id')->Verweise('id')->auf('Unternehmen');
und das wird nicht funktionieren: Schema::create('Unternehmen', function (Blueprint $Tabelle) { $table-> - Schritten('id'); Schema::create('jobs', function (Blueprint $Tabelle) { $table-> - Schritten('id'); $Tabelle->Ganzzahl('firm_id'); $Tabelle->fremden('firm_id')->Verweise('id')->auf('Unternehmen');

InformationsquelleAutor Yrtymd | 2016-11-29

Schreibe einen Kommentar