I am trying to insert values into my comments table and I am getting a error. Its saying that I can not add or update child row and I have no idea what that means.
m
that means that the value for column project_id
on table comments
you are inserting not only doesn't exist
on table projects BUT also project_id
probably doesn't have default value. E.g. in my case I set it as NULL.
As for Laravel you can consider this expressions as a chunk of code of a migration php file, for example:
class ForeinToPhotosFromUsers extends Migration
{ /** * Run the migrations. * * @return void */
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedBigInteger('photo_id')->nullable();// ! ! ! THIS STRING ! ! !
$table->foreign('photo_id')->references('id')->on('photos');
});
}
}
Obviously you had to create the Model class(in my case it was Photo) next to all these.