1054未知列「圖像」我有模型的文章,文件組,文件。柱未發現:在「字段列表」
時節省用圖像的新文章,它會顯示這個錯誤:
{"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 intoarticles
(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');
}
}
請確認是否列'image'在表中存在'articles' – ImAtWar
'image'和'web_image'不存在於您的文章遷移 – Nerea
image列不會在您的文章表遷移存在 –