In Laravel db migration commands; it is not possible to create a column which is BOTH unique and greater than 191 in size. How to solve?

246
August 31, 2017, at 11:40 PM

First; according to this

I edited: app\Providers\AppServiceProvider.php

public function boot()
{
   Schema::defaultStringLength(191);
}

Second; I issued php artisan make:migration create_users

Third; I implemented the generated class:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsers extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
           Schema::create('users2',function($users){
           $users->increments('id');
           $users->string('email',320)->unique(); // this causes errors
           $users->string('username',100)->unique();
           $users->string('password',50);
           $users->rememberToken();
           $users->timestamps();
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users2');
    }
}

Fourth; after issuing php artisan migrate

I get this result:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users2 add unique users2_email_unique(email))

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

The problem is in this line: $users->string('email',320)->unique();

When I check the database; I find the email column was created with the specified length 320 but NOT unique UNI

If length is set to 191 or less, then the email column is created properly with the specified length and uniqueness.

So how to allow the creation of columns which are both unique and not limited to the 191 ceiling?!

READ ALSO
PHP/PDO Select Statement with Multiple Bound Where Conditions Returning 500 Error

PHP/PDO Select Statement with Multiple Bound Where Conditions Returning 500 Error

This is the first time that I am trying to query mysql according to multiple where conditions in my PDO select statement and with several different approaches I am consistently getting a 500 internal error

257
When i submit, nothing happens, it just reloads my page [on hold]

When i submit, nothing happens, it just reloads my page [on hold]

I am new here and i have a questioni create simple login page When i submit, nothing happens, it just reloads my page

164