samedi 16 février 2019

Error no: 150 "Foreign key constraint is incorrectly formed"

I have ‘posts’ table and ‘arrival’ table which references ‘flightno’(in text string format) as foreign key. However when I run the Laravel migration I get the dreaded error code: [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1005 Can't create table atc.#sql-2350_84 (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table arrival add constraint arrival_flightno_foreign foreign key (flightno) references posts (flightno))

[PDOException] SQLSTATE[HY000]: General error: 1005 Can't create table atc.#sql-2350_84 (errno: 150 "Foreign key constraint is incorrectly formed")

This is my ‘posts’ table schema:

Schema::create('posts', function (Blueprint $table) {
                $table->increments('id');
                $table->string('flightno');
                $table->string('flighttype');
                $table->string('toa');
                $table->string('doa');
                $table->string('runway');
                $table->string('route');
                $table->string('parking');
                $table->timestamps();
        }); 


And this is my ‘arrival’ schema:
Schema::create('arrival', function (Blueprint $table) {
            $table->increments('id');
            $table->string('flightno');
            $table->string('cleaning');
            $table->string('rampservice');
            $table->string('waste');
            $table->string('deicing');
            $table->foreign('flightno')->references('flightno')->on('posts')->onDelete('cascade');
            $table->timestamps();
    });



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2tofRNR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire