SQL laravel 5.6 中的完整性约束错误

SQL integrity constraint error in laravel 5.6

目前正在使用 laravel 5.6 并且在更新我创建的表单时遇到问题。

完整的错误是:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: update `companies` set `name` = , `description` = this is a SE company., `updated_at` = 2018-12-16 10:05:55 where `id` = 1)

edit.blade.php 文件如下:

 <form method="post" action="{{route('companies.update',[$company->id]) }}">
        {{ csrf_field() }}

        <input type="hidden" name="_method" value="put">

        <div class="form-group">
            <label for="company-name">Name<span class="required">*</span></label>
            <input placeholder="Enter name"
                   id="company-name"
                   required
                   name="description"
                   spellcheck="false"
                   class="form-control"
                   value="{{ $company->name }}"
            />
        </div>

        <div class="form-group">
            <label for="company-content">Description</label>
            <textarea placeholder="Enter description"
                        style="resize:vertical"
                        name="description" 
                        id="company-content" 
                        rows="5" cols="5"
                        spellcheck="false"
                        class="form-control autosize-target text-left">
                        {{ $company->description}}
                    </textarea>
        </div>
        <div class="form-group">
            <input type="submit" class="btn btn-primary"
                    value="Submit"/>
        </div>

      </form>

这是迁移文件:

 public function up()
{
    Schema::create('companies', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->longText('description')->nullable();
        $table->integer('user_id')->unsigned();
        $table->timestamps();
    });
}

任何关于我做错了什么的指导将不胜感激。

(请注意,一旦包含您的 PHP 代码片段,我会立即更新我的答案,因为这可能是您出错的部分原因。)

您在输入元素中使用了错误的名称属性。您正在检查两次 description

改变这个:

<input placeholder="Enter name"
                   id="company-name"
                   required
                   name="description"
                   spellcheck="false"
                   class="form-control"
                   value="{{ $company->name }}"
            />

为此:

<input placeholder="Enter name"
                   id="company-name"
                   required
                   name="name"
                   spellcheck="false"
                   class="form-control"
                   value="{{ $company->name }}"
            />

您输入的属性名称不正确

<input placeholder="Enter name"
               id="company-name"
               required
               name="description" <!-- <<-- This should be "name" not "description" -->
               spellcheck="false"
               class="form-control"
               value="{{ $company->name }}"
/>

如果出于某种原因您希望名称可以为空

public function up()
{
    Schema::create('companies', function (Blueprint $table) {
        // ...   
        $table->string('name')->nullable(); // <<-- this is modified
        // ...
    });
}