0
当我尝试保存到数据库中,我不断收到在我的控制器这些错误Laravel数据保存到数据库模型SQLSTATE [23000]:完整性约束违规:19 NOT NULL约束失败:
PDOException in Connection.php line 479:
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: images.uploader
QueryException in Connection.php line 769:
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: images.uploader (SQL: insert into "images" ("name", "description", "updated_at", "created_at") values (coat, description test, 2016-12-11 10:34:34, 2016-12-11 10:34:34))
的存储功能
public function store($name)
{
$image = new Image;
$image->name = $name;
$image->description = "description test";
$image->save();
}
迁移
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->increments('id');
$table->string('uploader');
$table->string('name');
$table->string('description');
$table->integer('width');
$table->integer('height');
$table->decimal('size');
$table->integer('views')->default(0);
$table->string('extension');
$table->timestamps();
});
}
和我的模型
class Image extends Model
{
protected $fillable = ["name", "description"];
}
我不知道我在做什么错,我一直卡住这个太长。 我希望有人可以帮我
我看到所以我不填充的每一列都需要为空或者有一个空字符串的默认值 是对的吗? –
是的,基本上这些限制是为了确保你的数据库中有正确的数据。所以,如果你期望它是空的,你应该说明它 – SteD
好的,谢谢你的帮助^ _ ^ –