I'm making register form in laravel, first I create the migration
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
I want first to register name, email and password without first_name and last_name, but when I click register it gives me error that first_name and last_name don't have default values..so how to make default values null, because I want to update that columns later.
$table->string('first_name')->default('DEFAULT');
edit: if the default value is supposed to be null, make it nullable instead.
$table->string('first_name')->nullable();
In Laravel 5.8 you can try it in migration script as below;
public function up()
{
if (Schema::hasTable('table_name')) {
Schema::table('table_name', function (Blueprint $table) {
$table->string('column_name')->nullable();
});
}
}
Reference: https://laravel.com/docs/5.8/migrations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With