Hi, I'm new for Laravel. I installed Laravel and having trouble to migrate new table call tasks. My local env is running XAMPP on Window. The error is
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 `users`
add unique `users_email_unique`(`email`))
at C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
2 PDOStatement::execute()
C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
Please use the argument -v to see more details.
According to the Laravel Docs this problem occurs if you're using MariaDB or MySQL versions older than 5.7.7.
To fix the error, go to app/Providers/AppServiceProvider.php and add a boot function as follows. (Make sure to import the Schema facade from Illuminate\Support\Facades\Schema.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
The docs also say that you can enable innodb_large_prefix option in your database and the probelm should be fixed. If you're using MySQL I suggest you to upgrade to the latest version and not bother with any of the above.
Hi guys, I upgrade MariaDB to 10.2.13 It's working for Laravel version 5.4 but still facing problem for Laravel 5.6.9 as below.
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TE
XT column 'email' used in key specification without a key length (SQL: alter table `users` add unique `u
sers_email_unique`(`email`))
at C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'email' u
sed in key specification without a key length")
C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
2 PDOStatement::execute()
C:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php : 458
Please use the argument -v to see more details.
Are you trying to use a TEXT or BLOB type column as a primary key?
Edit:
I assume that you have assigned the BLOB or TEXT data type to your email column. Try changing the column type to VARCHAR(x). x is the maximum number of characters allowed. Laravel's users table uses a VARCHAR(255) for the email column.
@faizannoor@oladele Just realize you can't store all true UTF8 data (like emojis) with mysql's UTF8 charset. It isn't a full implementation of UTF8. utf8mb4 fixes that. Mysql's UTF8 only stores 3 bytes/character, while utf8mb4 is true UTF8 and stores 4 bytes/character, which things (like emojis/unicode) and other languages require.