I\'m trying to create a table to hold photos and link it to the ad (property id). I\'m getting this error
SQLSTATE[HY000]: General error: 1215 Cannot add
Make it unsigned
because you're using increments()
. And move FK constraint part to a separate closure:
public function up()
{
Schema::create('property_advert_photos', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('propertyadvert_id')->nullable();
$table->timestamps();
});
Schema::table('property_advert_photos', function (Blueprint $table) {
$table->foreign('propertyadvert_id')->references('id')->on('property_adverts');
});
}