php - Laravel "SQLSTATE[HY000]: General error: 1364 Field ' 登录'没有默认值...”

标签 php mysql laravel mysql-error-1364

在尝试了其他线程的所有现有解决方案后,我遇到了这个问题,但没有任何效果,例如:MySql Error: 1364 Field 'display_name' doesn't have default value如果我这样做 ->nullable() 我的所有插入内容都将为空。 这就是我的代码:

Controller :

<?php

namespace App\Http\Controllers;
use App\Utilisateur;

use Illuminate\Http\Request;

class UtilisateursController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('login.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            //'email' => 'required',
            'password' => 'required',
            //'password_confirmation' => 'required',
            //'telephone' => 'required'
          ]);
          $inscription = new Utilisateur([
            'Login' => $request->get('username'),
            'E-mail' => 'email',
            'Password' => $request->get('password'),
            'Telephone' => 'telephone',
            'created_at' => $request->get(date("Y-m-d H:i:s")),
            'updated_at' => $request->get(date("Y-m-d H:i:s"))
          ]);
          $inscription->save();
          return redirect()->route('login.create')->with('success', 'inscription réussite');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

型号:

    <?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Utilisateur extends Model
{
    protected $fillable = ['username', 'email', 'password', 'telephone'];
}

数据库:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUtilisateursTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('utilisateurs', function (Blueprint $table) {
            $table->increments('ID-User');
            $table->string('Login', 250);
            $table->string('Password', 250);
            $table->string('Telephone', 250);
            $table->string('E-mail', 250)->unique();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('utilisateurs');
    }
}

最佳答案

表中存在名为 display_name 的字段名称,或者应将其添加到模型中

关于php - Laravel "SQLSTATE[HY000]: General error: 1364 Field ' 登录'没有默认值...”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53981550/

相关文章:

php - 即使未分配空间,SQL 计数值也会返回 0

mysql - Laravel Homestead - 通过 SSH 隧道连接到远程数据库

sql - 不要在 Laravel Eloquent ORM 中使用准备好的语句?

php - 在 MySQL 中从 m 个数字的字符串中搜索匹配 n 个数字

mysql - 根据 Laravel 和 MySQL 是否为 null 按两列排序

Laravel 路线不适用于子文件夹

php - 使用 PHP 发布嵌套 JSON 时遇到问题

php - 为什么MySQL中会发生这种数据类型转换?

javascript - 使用 jQuery .load() 将一个页面的脚本部分加载到另一个页面中

MySQL Workbench - 改变数据库查询(本地连接数据库)