2016-11-15 124 views
1

我有三個表(服務,services_products,services_product_translation)Laravel:SQLSTATE [42S22]:列未找到:1054未知列

時嘗試插入新的產品,我得到這個錯誤

SQLSTATE [ 42S22]:列未發現:在1054未知列'services_products.services_product_id 'where子句'(SQL:從services_products其中services_products選擇* services_product_id = 3)。

這裏是我的遷移 服務遷移

Schema::create('services', function(Blueprint $table) 
      { 
       $table->increments('id'); 
       $table->binary('image'); 
       $table->timestamps(); 
      }); 

services_products遷移

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'); 
    } 
} 

ServicesProduct

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'); 
      } 
     } 
+1

它應該只是「services_products.id」嗎?我沒有看到您在遷移中提到的字段。 – Ronald

回答

1

的錯誤是自我解釋,存在services_products表名「services_product_id」目前沒有列。這就是它顯示錯誤的原因。

我想在條件列名就像services_products.id,因爲通常我們在那裏主列連接表,其主要列爲ID

0

發佈的答案我的評論:

它應該只是「services_products.id」嗎?我沒有看到您在遷移中提到的字段 。

相關問題