Error message :
[PDOException]The error caused by you missed creating the column "key_id" before you assign it as foreign key.
SQLSTATE[42000] : Syntax error or access violation: 1072 key column 'key_id' doesn't exists in table
There is the example with problem:
Schema::create('tables', function (Blueprint $table) {Corrected code:
$table->increments('d')->uniqlue();
$table->foreign('key_id',10)->references('news_id')->on('news')->nullable();
$table->string('title',30)->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::create('tables', function (Blueprint $table) {
$table->increments('d')->uniqlue();
$table->integer('key_id')->unsigned()->nullable();
$table->foreign('key_id',10)->references('news_id')->on('news')->nullable();
$table->string('title',30)->nullable();
$table->timestamps();
$table->softDeletes();
});
No comments :
Post a Comment