vendredi 2 septembre 2016

Laravel 5.3 Creating Models Returns "Field doesn't have a default value"

I'm using Laravel and Eloquent for two years and today I've decided to install a fresh Laravel 5.3 and try something with it.

I used an old database schema of mine and created my models, defined fillable columns. This is what my Page model looks like:

<?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 is a TEXT-type column on MySQL so if I don't pass any value to it when creating a model, it should be a empty string. Instead, I keep getting SQLSTATE[HY000]: General error: 1364 Field 'url' doesn't have a default value error.

Here is my attempt to create a Post model:

Page::create([
    'title' => $root_menu['title'],
    'slug' => $root_menu['slug'],
    'language' => $this->language,
    'wireframe' => key(config('cms.wireframe')),
    'order' => 0
]);

Is this a Laravel 5.3 related issue or am I missing something? Thanks in advance for your helps.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire