php - Laravel 5.6 中的 SQL 完整性约束错误

标签 php mysql 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 代码片段,我就会更新我的答案,因为这可能是您错误原因的一部分。)

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

更改此:

<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 }}"
            />

关于php - Laravel 5.6 中的 SQL 完整性约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53801292/

相关文章:

php - 在选择查询中使用整数变量

c# - 在 C# 中连接到 phpmyadmin Web 服务器 xampp

mysql - Laravel-如何插入已在 mysql 中创建外键的多对多相关表?

javascript - Jquery ajax 在 laravel 5.6 中不起作用

php - Passport 通过访问 token 获取用户 Laravel 5.3

php - Laravel Homestead 文件夹映射无法正常工作

php - 我们可以在 php 中将 Redis 与队列一起使用吗

PHP 术语 : difference between getters and public methods?

php - 作业跟踪的批处理通知

mysql - 如何在此 MySQL 查询中使用 CASE?