【问题标题】:how to solve this php laravel database problem [closed]如何解决这个php laravel数据库问题[关闭]
【发布时间】:2020-01-20 20:18:16
【问题描述】:

SQLSTATE[23000]:违反完整性约束:1048 列 “publication_status”不能为空(SQL:插入categories (category_name, category_description, publication_status, updated_at, created_at) 价值观 (saiful, good human, , 2020-01-20 20:07:52, 2020-01-20 20:07:52))

【问题讨论】:

  • 错误很明显。您没有为publication_status 提供值,而您的数据库正在期待一个值。所以解决这个问题。
  • 你有5个列名和5个值,但是publication_status列是not null列,所以你必须提供值

标签: php database laravel


【解决方案1】:

您需要为 publication_status 设置一个值或修改数据库中的列以允许 NULL 值。

要允许 NULL 值,您可以通过运行以下命令创建迁移:php artisan make:migration allow_publication_status_nullable_to_categories_table

然后打开新的迁移文件并添加:

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('categories', function (Blueprint $table) {
            //I'm assuming that the column publication_status is a integer
            //if not, just change it to the correct column type
            $table->integer('publication_status')->nullable()->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('categories', function (Blueprint $table) {
            $table->integer('publication_status')->nullable(false)->change();
        });
    }

终于运行php artisan migrate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2020-10-21
    • 2019-07-03
    • 2017-07-02
    • 1970-01-01
    • 2020-10-03
    • 2021-11-20
    相关资源
    最近更新 更多