So I get this error:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table
yamldb
.#sql-3928_6ea
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tabletblquestion
add constrainttblquestion_que_csd_id_foreign
foreign key (que_csd_id
) referencestblcsdomain
(csd_id
))
Table 1
Schema::create('tblquestion', function (Blueprint $table) {
$table->increments('que_id');
$table->string('que_name', 128);
$table->string('que_identifier', 128);
$table->string('que_version', 50);
$table->char('que_content');
$table->char('que_answers');
$table->integer('que_grd_id')->unsigned();
$table->integer('que_quf_id')->unsigned();
$table->integer('que_lan_id')->unsigned();
$table->boolean('que_mandatory', false);
$table->char('que_thisisinformatics');
$table->char('que_translations');
$table->char('que_explanation');
$table->char('que_background_info');
$table->integer('que_cou_id')->unsigned();
$table->boolean('que_allow_share', false);
$table->integer('que_source_cou_id')->unsigned();
$table->integer('que_source_que_id');
$table->mediumInteger('que_csd_id')->unsigned();
$table->string('que_token', 32);
});
Table 2
Schema::create('tblcsdomain', function (Blueprint $table) {
$table->increments('csd_id');
$table->string('csd_name', 128);
$table->string('csd_token', 128);
});
Migration
Schema::table('tblquestion', function (Blueprint $table) {
$table->foreign('que_csd_id')->references('csd_id')->on('tblcsdomain');
}
Also I am trying to add FK to already existing columns. And Laravel adds the FK but on rollback it doesn't remove them.
Schema::table('tblquestion', function (Blueprint $table) {
$table->dropForeign(['que_csd_id']);
}