Ad

Laravel Error Add Photo_id To My Migration

- 1 answer

i'm trying to add a photo to my scooter advertisement. but when i'm trying to migrate i get this error the whole time:

   Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'photo_id' doesn't exist in table (SQL: alter table `scooter` add constraint `scooter_photo_id_foreign` foreign key (`photo_id`) references `photo` (`id`))

i do not get what i'm doing wrong.

scooter migration class CreateScooterTable extends Migration {

public function up()
{
    Schema::create('scooter', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->foreign('photo_id')->references('id')->on('photo');
        $table->string("price");
        $table->bigInteger("description");
        $table->string("km");
        $table->string("lincenseplatecolor");
        $table->string("color");
        $table->string("name");
        $table->boolean("sold");
        $table->string("motortype");
        $table->string("brand");
        $table->string("topspeed");
        $table->string("contstructionYear");
        $table->timestamps();
    });
}

public function down()
{
    Schema::dropIfExists('scooter');
}

} photo migration:

class CreatePhotoTable extends Migration

{

public function up()
{
    Schema::create('photo', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('src');
        $table->timestamps();
    });
}


public function down()
{
    Schema::dropIfExists('photo');
}

}

i do not get what i'm doing wrong and love if you guys would know the awnser (:

Ad

Answer

The answer was that I had to change the time stamps in the filename. that way photo id existed when people wanted create a new relation.

Ad
source: stackoverflow.com
Ad