I have just started learning laravel
. I'm familiar with CakePHP
.
I used to use UUID
field as primary key in my database and in CakePHP, it was quite simple to just change data type of column field to CHAR(36)
and it works well.
In Laravel, I have modified users
migration to change increments
to uuid
field and set to primary key
CreateUserTable
<?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->uuid('id');
$table->primary('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::table('users', function (Blueprint $table) {
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->uuid('role_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
But, when I save a new record, it gives error as
Illuminate\Database\QueryException thrown with message
"SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value
(SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`)
values (Anuj, anuj@example.com, password_hash, date-time, date-time))"
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mVs8GY
via IFTTT
Aucun commentaire:
Enregistrer un commentaire