我使用 Laravel 和 Eloquent 已经两年了,今天我决定安装一个新的 Laravel 5.3 并尝试一下。
我使用了我的旧数据库模式并创建了我的模型,定义了可填充的列。这是我的Page
模型的样子:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'language',
'title',
'slug',
'url',
'description',
'tags',
'wireframe',
'order',
'is_active'
];
public function menus()
{
return $this->belongsToMany(Menu::class);
}
}
url
attribute 是TEXT
MySQL 上的一个 -type 列,因此如果我在创建模型时不向它传递任何值,它应该是一个空字符串。相反,我不断收到SQLSTATE[HY000]: General error: 1364 Field 'url' doesn't have a default value
错误。
这是我创建 Post 模型的尝试:
Page::create([
'title' => $root_menu['title'],
'slug' => $root_menu['slug'],
'language' => $this->language,
'wireframe' => key(config('cms.wireframe')),
'order' => 0
]);
这是与 Laravel 5.3 相关的问题还是我遗漏了什么?提前感谢您的帮助。