SQLSTATE[42S22]: Column not found: 1054 Unknown column material_tags.material_uuid

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



SQLSTATE[42S22]: Column not found: 1054 Unknown column material_tags.material_uuid



I have searched for people who encountered this error but I still can't find the solution.



I have been getting the error:



"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'material_tags.material_uuid' in 'field list' (SQL: select tags.*, material_tags.material_uuid as pivot_material_uuid, material_tags.tag_uuid as pivot_tag_uuid from tags inner join material_tags on tags.uuid = material_tags.tag_uuid where material_tags.material_uuid in (05a36470-d0a0-11e7-91b4-ff3d7d9f961a) and tags.deleted_at is null)"


tags


material_tags


material_uuid


pivot_material_uuid


material_tags


tag_uuid


pivot_tag_uuid


tags


material_tags


tags


uuid


material_tags


tag_uuid


material_tags


material_uuid


tags


deleted_at



in which if I have to view Material 05a36470-d0a0-11e7-91b4-ff3d7d9f961a it should look like this
enter image description here



When I try to run this code located on the controller:


public function show(Request $request, $id)
{
$material = Material::with('tags')->where(
'uuid',
$id
)->first();



where my Material Model has this:


public function tags()

return $this->belongsToMany('AppModelsTag', 'material_tags');




So I have a Tags table where all the tags are stored, and a Materials table that has all the materials stored. and I have the Material_tags table to see what Materials have tags.



my create_materials_table at migration


public function up()

Schema::connection('materials')->create('materials', function (Blueprint $table)
$table->uuid('uuid')
->primary();
$table->string('title');
$table->integer('viewing_time')
->default(15)
->comment('In seconds');
$table->text('description')
->nullable();
$table->uuid('organization_id')
->nullable();

$table->timestamps();
$table->softDeletes();
);



my create_tags_table migration


public function up()

Schema::connection('materials')->create('tags', function (Blueprint $table)
$table->uuid('uuid')
->primary();
$table->string('name')
->unique();

$table->timestamps();
$table->softDeletes();
);



and my create_material_tags_table migration


public function up()

Schema::connection('materials')->create('material_tags', function (Blueprint $table)
$table->uuid('uuid')
->primary();
$table->uuid('material_id');
$table->uuid('tag_id');

$table->timestamps();

$table->foreign('material_id')
->references('uuid')
->on('materials')
->onDelete('cascade');
$table->foreign('tag_id')
->references('uuid')
->on('tags')
->onDelete('cascade');
);




1 Answer
1



You have to specify the custom foreign keys:


public function tags()

return $this->belongsToMany('AppModelsTag', 'material_tags', 'material_id', 'tag_id');





thank you very much! I have been dealing with this for days. Thank you!
– eibersji
Aug 7 at 2:18






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS