首页 > 解决方案 > 如何使用迁移在没有 created_at 和 Updated_at 列的 laravel 中创建表

问题描述

任何人都可以知道如何在 laravel 中创建表,而无需使用迁移表中的 created_at 和 Updated_at 列。我尝试以下代码,但它仍然在表中创建 created_at 和 Updated_at 列:-

迁移 Laravel:-

<?php

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

class CreateNewusersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('newusers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('name');
            $table->string('email', 100)->unique();
            $table->bigInteger('phone_no');
        });
    }

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

标签: laraveldatabase-migration

解决方案


将此添加到您的模型中

public $timestamps = false;

推荐阅读