Syntax error or access violation: 1072 Key column 'collection_id' doesn't exist in table (SQL: alter table products
add constraint products_collection_id_foreign
foreign key (collection_id
) references collections
(id
) on delete cascade)
So im having this issue trying to relation products with collections with a collection_id.
This is my collection migration
class CreateCollectionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('collections', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->string('author');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('collections');
}
}
This is my product migration
class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->integer('price');
$table->string('src');
$table->unsignedBigInteger('collection_id');
$table->foreign('collection_id')->references('id')->on('collections')->onDelete("cascade");
$table->integer('amount');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}