0

Hi I just started a new project in laravel so it's the latest version 5.4, I'm getting an error when seeding to the database for a single user and I'm getting this error

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 1000 bytes (SQL: alter table users add unique users_email_unique(email))

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 1000 bytes

User::create([
    'name' => 'someone'
    'email' => 'someone@outlook.com',
    'password' => bcrypt('mypassword'), 
]);


<?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('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
ONYX
  • 5,679
  • 15
  • 83
  • 146
  • 2
    Possible duplicate of [Laravel migration: unique key is too long, even if specified](https://stackoverflow.com/questions/23786359/laravel-migration-unique-key-is-too-long-even-if-specified) – Tim Biegeleisen Aug 18 '17 at 01:38
  • Your question appears to be a close duplicate of the link above. – Tim Biegeleisen Aug 18 '17 at 01:39

1 Answers1

0

You should try this like:

use  Illuminate\Support\Facades\Schema; // At the top of your file

And add this line in the boot() method of the AppServiceProvider :

Schema::defaultStringLength(191);
halfer
  • 19,824
  • 17
  • 99
  • 186
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57