Php Laravel:SQLSTATE[42S22]:未找到列:1054未知列
我有三张桌子(服务、服务产品、服务产品翻译) 当尝试插入新产品时,我遇到此错误 SQLSTATE[42S22]:未找到列:1054“where子句”中的未知列“services\u products.services\u product\u id”(SQL:select*fromPhp Laravel:SQLSTATE[42S22]:未找到列:1054未知列,php,mysql,laravel,eloquent,database-migration,Php,Mysql,Laravel,Eloquent,Database Migration,我有三张桌子(服务、服务产品、服务产品翻译) 当尝试插入新产品时,我遇到此错误 SQLSTATE[42S22]:未找到列:1054“where子句”中的未知列“services\u products.services\u product\u id”(SQL:select*fromservices\u productswhereservices\u products=3) 这是我的迁移 服务迁移 Schema::create('services', function(Blueprint $tabl
services\u products
whereservices\u products
=3)
这是我的迁移
服务迁移
Schema::create('services', function(Blueprint $table)
{
$table->increments('id');
$table->binary('image');
$table->timestamps();
});
Schema::create('services_products', function(Blueprint $table)
{
$table->increments('id');
$table->integer('service_id')->unsigned();
$table->binary('image');
$table->binary('pdf');
$table->foreign('service_id')->references('id')->on('services')->onDelete('cascade');
$table->timestamps();
});
服务和产品迁移
Schema::create('services', function(Blueprint $table)
{
$table->increments('id');
$table->binary('image');
$table->timestamps();
});
Schema::create('services_products', function(Blueprint $table)
{
$table->increments('id');
$table->integer('service_id')->unsigned();
$table->binary('image');
$table->binary('pdf');
$table->foreign('service_id')->references('id')->on('services')->onDelete('cascade');
$table->timestamps();
});
这是翻译表
Schema::create('services_product_translations', function(Blueprint $table)
{
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->string('title', 150);
$table->longText('details');
$table->string('locale')->index();
$table->unique(['product_id', 'locale']);
$table->foreign('product_id')->references('id')->on('services_products')->onDelete('cascade');
});
这是我的模型
服务
class Service extends \Eloquent
{
use \Dimsav\Translatable\Translatable;
public $translatedAttributes = ['title', 'brief'];
public $translationModel = 'ServicesTranslation';
public function servicesPro()
{
return $this->hasMany('ServicesProduct', 'service_id');
}
}
服务产品
class ServicesProduct extends \Eloquent
{
use \Dimsav\Translatable\Translatable;
public $translatedAttributes = ['title', 'details'];
public $translationModel = 'ServicesProductTranslation';
public function services()
{
return $this->belongsTo('Service', 'service_id');
}
public function proImage()
{
return $this->hasMany('ServicesProductImage', 'image_id');
}
public function proVideo()
{
return $this->hasMany('ServicesProductVideo', 'video_id');
}
这是我用来存储的控制器
public function store()
{
$sev_id = Input::get('category');
$file = Input::file('image');
$pdf = Input::file('pdf');
$destination_path = 'images/servicesProductsImages/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$file->move($destination_path, $filename);
$destination_path_pdf = 'images/servicesProductsPdf/';
$filenamePdf = str_random(6) . '_' . $pdf->getClientOriginalName();
$pdf->move($destination_path_pdf, $filenamePdf);
$newSerPro = new ServicesProduct();
$newSerPro->service_id = $sev_id;
$newSerPro->image = $filename;
$newSerPro->pdf = $filenamePdf;
$newSerPro->save();
$localization = Input::get('localization');
$locales = array_keys($localization);
foreach ($locales as $locale) {
if (!in_array($locale, array('en', 'ar'))) {
Session::flash('message', 'Lang Error');
return Redirect::to('admin/create-service-sub-category');
}
}
错误是不言自明的,在
services\u products
表中没有名称为services\u product\u id
的列。这就是它显示错误的原因
我认为条件中的列名类似于
services\u products.id
,因为通常我们在主列上联接表,其主列是id
将我的评论作为答案发布:
是否应该只使用“services\u products.id”?我没有看见你的田地
在您的迁移中提到
是否应该只使用“services\u products.id”?我没有看到您在迁移中提到的字段。