2017-06-27 19 views
1

私はモデルArticle、Filegroup、Fileを持っています。カラムが見つかりません:1054 'フィールドリスト'の 'image'が不明です

イメージを持つ新しい記事保存、それはこのエラーが表示されます。

{"exception":"Illuminate\Database\QueryException","message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'image' in 'field list' (SQL: insert into articles (title , text , like_count , view_count , comment_count , image , web_image , updated_at , created_at) values (dsvdscdscdscsdcdsc, sacsaxasxsaxsaxsaxsaxsax, 0, 0, 0, 11, 13989, 2017-06-27 15:40:49, 2017-06-27 15:40:49))","trace":[{"file":"/var/www/laravel/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php","line":726,"function":"runQueryCallback","class":"Illuminate\Database\Connection","type":"->","args":["insert into articles (title , text , like_count , view_count , comment_count , image , web_image , updated_at , created_at) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",..................

モデル/ Article.php

namespace App\Models; 

use Illuminate\Database\Eloquent\Model; 

class Article extends Model 
{ 
    protected $guarded = ['id']; 
    protected $with = ['image']; 

    public function image() 
    { 
     return $this->belongsTo('App\Models\Filegroup', 'image_id'); 
    } 
} 

モデル/ FileGroup.php

use Illuminate\Database\Eloquent\Model; 

class Filegroup extends Model 
{ 
    protected $table = 'file_groups'; 

    protected $with = ['files', 'name']; 

    protected $guarded = ['id']; 

    /** 
    * One-to-Many relations with SiteString. 
    * 
    * @foreignModel SiteString 
    * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 
    */ 
    public function name() 
    { 
     return $this->belongsTo('App\Models\SiteString', 'name_id'); 
    } 

    /** 
    * Many-to-Many relations with File. 
    * 
    * @foreignModel File 
    * @return \Illuminate\Database\Eloquent\Relations\HasMany 
    */ 
    public function files() 
    { 
     return $this->hasMany('App\Models\File', 'filegroup_id'); 
    } 
} 

移行して作成されたモデル/ file.php

namespace App\Models; 

use Illuminate\Database\Eloquent\Model; 

class File extends Model 
{ 
    protected $table = 'files'; 

    protected $fillable = [ 
     'mimi_type', 
     'path', 
     'width', 
     'height', 
     'size' 
    ]; 

    /** 
    * One-to-Many inverse relations with Filegroup. 
    * 
    * @foreignModel Filegroup 
    * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 
    */ 
    public function group() 
    { 
     return $this->belongsTo('App\Models\Filegroup', 'filegroup_id'); 
    } 
} 

テーブルの記事:

class CreateArticlesTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('articles', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->integer('image_id'); 
      $table->text('text'); 
      $table->string('title'); 
      $table->integer('like_count'); 
      $table->integer('view_count'); 
      $table->integer('comment_count'); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::dropIfExists('articles'); 
    } 
} 
+0

テーブル 'articles'に「image」列が存在するかどうか確認してください – ImAtWar

+1

記事の移行に' image'と 'web_image'は存在しません – Nerea

+0

記事列は記事テーブルの移行に存在しません –

答えて

0

あなたは$guardedモデルの属性ではなく、$fillableを使用している場合は、それは属性のすべての値を試してみて、挿入しますあなたのモデルの配列。ここでその上より:https://laravel.com/docs/5.4/eloquent#mass-assignment

あなたは、あなたの記事のモデルに代入している属性の配列のみが対応するデータベースの列を持っているか、あなたがそうのよう$fillableに切り替えることができる属性が含まれていることを確認することができ、次のいずれか

protected $fillable = [ 
    'image_id', 
    'text', 
    'title', 
    'like_count', 
    'view_count', 
    'comment_count', 
]; 
関連する問題