php - SQL Foreign Key General Error 1215 when creating migrations -
i built 2 migrations:
public function up() { schema::create('incidents', function (blueprint $table) { $table->increments('id'); $table->string('user_id'); $table->integer('incident_type_id')->unsigned(); $table->string('type'); $table->string('incident_reference'); $table->integer('incident_id'); $table->date('date'); $table->time('time'); $table->string('location'); $table->string('street'); $table->string('city'); $table->double('latitude', 10, 6); $table->double('longitude', 10, 6); $table->smallinteger('incident_archived')->default(0); $table->timestamps(); }); }
and other one:
public function up() { schema::create('responders', function (blueprint $table) { $table->increments('id'); $table->string('user_id'); $table->string('responder_id'); $table->integer('incident_id'); $table->foreign('incident_id')->references('incident_id')->on('incidents'); $table->double('last_lat', 10, 6); $table->double('last_lng', 10, 6); $table->timestamps(); }); }
now want use incident_id foreign key incidents table. error: cannot add foreign key constraint. first thought order of migrations causes trouble, responder table created before incident table. not case. why blocked using incident_id foreign key then?
thank you
Comments
Post a Comment