mercredi 22 août 2018

Laravel : foreign key -> doesn't have a default value


Hi ! I read other questions but I don't find my answer.
I want to create data but give me this error:

SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value

Controller:

public function store(BannerRequest $request)
    {
        Banner::create($request->all());

        flash()->success('Success', 'Your banner has been created.');

        return back(); // temporary
    }

and Table:

Schema::create('banners', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
            $table->string('street', 40);
            $table->string('city', 40);
            $table->string('zip', 15);
            $table->string('country', 40);
            $table->string('state', 40);
            $table->integer('price');
            $table->text('description');
            $table->timestamps();
        });

Thank for your helps.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire