【发布时间】:2019-01-13 01:23:13
【问题描述】:
我已经搜索过遇到此错误的人,但我仍然找不到解决方案。
我收到了错误:
"SQLSTATE[42S22]: 未找到列: 1054 '字段列表'中的未知列 'material_tags.material_uuid' (SQL: select
tags.*,material_tags.material_uuidaspivot_material_uuid, @987654327 @.tag_uuidaspivot_tag_uuidfromtagsinner joinmaterial_tagsontags.uuid=material_tags.tag_uuidwherematerial_tags.material_uuidin (00-a--d 91b4-ff3d7d9f961a) 和tags.deleted_at为空)"
如果我必须查看材料 05a36470-d0a0-11e7-91b4-ff3d7d9f961a 它应该是这样的
当我尝试在控制器上运行此代码时:
public function show(Request $request, $id)
{
$material = Material::with('tags')->where(
'uuid',
$id
)->first();
我的材料模型有这个:
public function tags()
{
return $this->belongsToMany('App\Models\Tag', 'material_tags');
}
所以我有一个存储所有标签的标签表,以及一个存储所有材料的材料表。我有 Material_tags 表来查看哪些材料有标签。
迁移时我的 create_materials_table
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();
});
}
我的 create_tags_table 迁移
public function up()
{
Schema::connection('materials')->create('tags', function (Blueprint $table) {
$table->uuid('uuid')
->primary();
$table->string('name')
->unique();
$table->timestamps();
$table->softDeletes();
});
}
还有我的 create_material_tags_table 迁移
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');
});
}
【问题讨论】:
标签: php sql laravel-5 phpmyadmin