Laravel migration: unique key is too long, even if specified
I am trying to migrate a users table in Laravel. When I run my migration I get this error:
[IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error
or access violation: 1071 Specified key was too long; max key length
is 767 bytes (SQL: alter tableusers
add unique
users_email_uniq(
my migration is as follows:
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);
$table->string('role', 32);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(true);
$table->timestamps();
$table->unique('email', 'users_email_uniq');
});
After some googling I came across this bug report where Taylor says you can specify the index key as the 2nd parameter of unique()
, which I have done. It still gives the error. What is going on here?
php mysql laravel
|
show 1 more comment
I am trying to migrate a users table in Laravel. When I run my migration I get this error:
[IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error
or access violation: 1071 Specified key was too long; max key length
is 767 bytes (SQL: alter tableusers
add unique
users_email_uniq(
my migration is as follows:
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);
$table->string('role', 32);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(true);
$table->timestamps();
$table->unique('email', 'users_email_uniq');
});
After some googling I came across this bug report where Taylor says you can specify the index key as the 2nd parameter of unique()
, which I have done. It still gives the error. What is going on here?
php mysql laravel
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
1
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
1
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
1
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40
|
show 1 more comment
I am trying to migrate a users table in Laravel. When I run my migration I get this error:
[IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error
or access violation: 1071 Specified key was too long; max key length
is 767 bytes (SQL: alter tableusers
add unique
users_email_uniq(
my migration is as follows:
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);
$table->string('role', 32);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(true);
$table->timestamps();
$table->unique('email', 'users_email_uniq');
});
After some googling I came across this bug report where Taylor says you can specify the index key as the 2nd parameter of unique()
, which I have done. It still gives the error. What is going on here?
php mysql laravel
I am trying to migrate a users table in Laravel. When I run my migration I get this error:
[IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error
or access violation: 1071 Specified key was too long; max key length
is 767 bytes (SQL: alter tableusers
add unique
users_email_uniq(
my migration is as follows:
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);
$table->string('role', 32);
$table->string('confirmation_code');
$table->boolean('confirmed')->default(true);
$table->timestamps();
$table->unique('email', 'users_email_uniq');
});
After some googling I came across this bug report where Taylor says you can specify the index key as the 2nd parameter of unique()
, which I have done. It still gives the error. What is going on here?
php mysql laravel
php mysql laravel
asked May 21 '14 at 14:35


harrygharryg
8,6283289159
8,6283289159
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
1
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
1
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
1
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40
|
show 1 more comment
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
1
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
1
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
1
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
1
1
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
1
1
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
1
1
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40
|
show 1 more comment
33 Answers
33
active
oldest
votes
1 2
next
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
4
Maximum possible email length is254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.
– Sebastian Sulinski
Feb 3 '17 at 8:39
11
For Laravel 5.4, useIlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path
– webcoder
Mar 4 '17 at 4:05
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
|
show 1 more comment
Update 1
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Update 2
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
Solution
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4
support for 😀 then start to fix 😂 your database configuration.
In Laravel config/database.php
define:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC
allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld]
# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1
For clients:
[mysql]
default-character-set=utf8mb4
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld
sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just indatabase.php
config file and it will impact local Laravel project. Be sure todelete
database before making changes and create it with new settings. You need to changemy.cnf
config file only for global server side changes (currently all new installations useutf8mb4
).
– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passingoptions={"row_format"="DYNAMIC"}
to your@Table
annotation.
– Albert221
Feb 20 '17 at 19:22
|
show 2 more comments
If you're on or updated to Laravel 5.4 This worked for me;
Just 1 change. in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
As mentioned in the migrate guide https://laravel.com/docs/master/migrations#creating-indexes
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
add a comment |
If anyone else stumbles upon this answer like I did but for a different reason, you may check your Laravel DB charset/collation.
I was installing an application (Snipe-IT) and had configured the Laravel database config to use the following:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
Removing mb4
from both strings fixed the issue, although I believe Antonio's answer is the real solution to the problem.
add a comment |
This worked for me:
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
add a comment |
Remove mb4 from charset and collation from config/database.php, then it will execute successfully.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
For laravel 5.4, simply edit file
AppProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
I have faced the same issue, and fixed it by adding the below two lines in my app/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
My file looks like below :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
......
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
add a comment |
For laravel 5.6
This solution solve my problem
go to config/database.php
Find the code below
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Change this two field
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'
With This
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
add a comment |
File: config/database.php
change the following
FROM ->
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
TO ->
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
add a comment |
In file config/database.php where :
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Change this line to this :
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
i had same problem and i am using a wamp
Solution :
Open file :
config/database.php
'engine' => null, => 'engine' => 'InnoDB',
Thanks
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
add a comment |
I added to the migration itself
Schema::defaultStringLength(191);
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
yes, I know I need to consider it on every migration but I would rather that than have it tucked away in some completely unrelated service provider
add a comment |
for laravel 5.7 write these code in appserviceprovider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
It's because Laravel 5.4 uses utf8mb4 which supports storing emojis.
Add this in your appProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
and you should be good to go.
add a comment |
If you're on or updated to Laravel 5.4 and latest version it works;
Just 1 change in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
add a comment |
If someone having this problem even after doing, above mentioned changes. For an example, in my case I did below changes,
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
But it wouldn't work right away for two reasons. One is if you are using lumen instead of laravel, you may have to uncomment this line in your app.php file first.
$app->register(AppProvidersAppServiceProvider::class);
And then you have to create the migration script again with the artisan command,
php artisan make:migration <your_table_name>
Since now only the changes you made to ServiceProvider will work.
add a comment |
For Laravel >= 5.6 users
Open AppServiceProvider.php
file
Use the following class
use IlluminateSupportFacadesSchema;
Then inside boot
method add the following line
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
Change charset to from 'utf8mb4' to 'utf8' and
collation to 'utf8mb4_unicode_ci' to 'utf8_unicode_ci'
in config/database.php file
It worked for me.
add a comment |
Laravel uses the utf8mb4
character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength
method within your AppServiceProvider
:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
You can check out of
https://laravel-news.com/laravel-5-4-key-too-long-error
https://laravel.com/docs/5.5/migrations#indexes
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
add a comment |
I'd like to point that something that i missed ...
I'm new at Laravel, and i didn't copy the "use Illuminate....." because i really didn'at paid atention, because right above the function boot you alread have a use Statement.
Hope that helps anyone
**use IlluminateSupportFacadesSchema;**
public function boot()
{
Schema::defaultStringLength(191);
}
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
add a comment |
I had a problem, change the configuration of the 'config / database'
file 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
keeping the same pattern in the database.
I then gave the command
php artisan migrate
add a comment |
In 24 october 2016 Taylor Otwell the Author of Laravel announced on is Twitter
"utf8mb4" will be the default MySQL character set in Laravel 5.4 for better emoji support. 🙌 Taylor Otwell Twitter Post
which before version 5.4 the character set was utf8
During this century many web app, include chat or some kind platform to allow their users to converses, and many people like to use emoji or smiley. and this are some kind of super characters that require more spaces to be store and that is only possible using utf8mb4
as the charset. That is the reason why they migrate to utf8mb4
just for space purpose.
if you look up in the IlluminateDatabaseSchemaBuilder
class you will see that the $defaultStringLength
is set to 255, and to modify that you can procede through the Schema
Facade and call the defaultStringLength
method and pass the new length.
to perform that change call that method within your AppServiceProvider
class which is under the appproviders subdirectory like this
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// all other code ...
Schema::defaultStringLength(191);
}
// and all other code goes here
}
I will suggest to use 191 as the value just because MySQL support 767 bytes, and because 767 / 4
which is the number of byte take by each multibyte character you will get 191
.
You can learn more here
The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
Limits on Table Column Count and Row Size
This is the only answer that explains the191
magic number.
– Illya Moskvin
Mar 5 at 17:50
add a comment |
You will not have this problem if you're using MySQL 5.7.7+ or MariaDB 10.2.2+.
To update MariaDB on your Mac using Brew first unlink the current one:
brew unlink mariadb
and then install a dev one using brew install mariadb --devel
After installation is done stop/start the service running:
brew services stop mariadb
brew services start mariadb
Current dev version is 10.2.3. After the installation is finished you won't have to worry about this anymore and you can use utf8mb4 (that is now a default in Laravel 5.4) without switching back to utf8 nor editing AppServiceProvider as proposed in the Laravel documentation: https://laravel.com/docs/master/releases#laravel-5.4 (scroll down to: Migration Default String Length)
add a comment |
Just installed MariaDB 10.2.4 RC, fired up new blank Laravel 5.4 project and default migration (varchar(255) columns) works.
No need to change DB conf and Laravael config/database.php
. Thus just as @scorer noted about default behaviour for 10.2.2+.
add a comment |
All was well described in the others Anwser
you can see more details in the link bellow (search with key 'Index Lengths & MySQL / MariaDB")
https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what this answer is about! the thing is even with doing the above you will like get another error (that's when you like launch php artisan migrate
command and because of the problem of the length, the operation like stuck in the middle. solution is bellow, and the user table is like created without the rest or not totally correctly)
we need to roll back. the default roll back will not do. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.
we can do it using tinker as in bellow:
L:todos> php artisan tinker
Psy Shell v0.8.15 (PHP 7.1.10 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
I myself had a problem with users table.
after that your good to go
php artisan migrate:rollback
php artisan migrate
add a comment |
Set database engine InnoDB:
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
add a comment |
If you have tried every other answer and they have not worked, you can drop all tables from the database and then execute the migrate command all at once using this command:
php artisan migrate:fresh
add a comment |
If you are seeing this error then definitely you need to make following changes on
AppServiceProvider.php
file -> which can be found inside app->providers:
changes to be made
use IlluminateSupportFacadesSchema; //see if you have this class if not add it.
public function boot()
{
Schema::defaultStringLength(191); //make sure you add this line
}
this should solve your problem for more you can see the Laravel news regarding this issue.
https://laravel-news.com/laravel-5-4-key-too-long-error
add a comment |
SOLUTION:
First change the defaultStringLength to 191, in the appProvidersAppServiceProvider.php:
public function boot()
{
Schema::defaultStringLength(191);
}
Then, change the charset and collation values as follows, in configdatabase.php:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
(link to know about MariaDB charset)
add a comment |
1 2
next
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: false,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23786359%2flaravel-migration-unique-key-is-too-long-even-if-specified%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
StackExchange.ready(function () {
$("#show-editor-button input, #show-editor-button button").click(function () {
var showEditor = function() {
$("#show-editor-button").hide();
$("#post-form").removeClass("dno");
StackExchange.editor.finallyInit();
};
var useFancy = $(this).data('confirm-use-fancy');
if(useFancy == 'True') {
var popupTitle = $(this).data('confirm-fancy-title');
var popupBody = $(this).data('confirm-fancy-body');
var popupAccept = $(this).data('confirm-fancy-accept-button');
$(this).loadPopup({
url: '/post/self-answer-popup',
loaded: function(popup) {
var pTitle = $(popup).find('h2');
var pBody = $(popup).find('.popup-body');
var pSubmit = $(popup).find('.popup-submit');
pTitle.text(popupTitle);
pBody.html(popupBody);
pSubmit.val(popupAccept).click(showEditor);
}
})
} else{
var confirmText = $(this).data('confirm-text');
if (confirmText ? confirm(confirmText) : true) {
showEditor();
}
}
});
});
33 Answers
33
active
oldest
votes
33 Answers
33
active
oldest
votes
active
oldest
votes
active
oldest
votes
1 2
next
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
4
Maximum possible email length is254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.
– Sebastian Sulinski
Feb 3 '17 at 8:39
11
For Laravel 5.4, useIlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path
– webcoder
Mar 4 '17 at 4:05
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
|
show 1 more comment
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
4
Maximum possible email length is254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.
– Sebastian Sulinski
Feb 3 '17 at 8:39
11
For Laravel 5.4, useIlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path
– webcoder
Mar 4 '17 at 4:05
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
|
show 1 more comment
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
Specify a smaller length for your e-mail:
$table->string('email', 250);
Which is the default, actually:
$table->string('email');
And you should be good.
For Laravel 5.4 you can find a solution in this Laravel 5.4: Specified key was too long error, Laravel News post:
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
edited Jan 28 '17 at 17:56
answered May 21 '14 at 14:42
Antonio Carlos RibeiroAntonio Carlos Ribeiro
68k13174180
68k13174180
4
Maximum possible email length is254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.
– Sebastian Sulinski
Feb 3 '17 at 8:39
11
For Laravel 5.4, useIlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path
– webcoder
Mar 4 '17 at 4:05
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
|
show 1 more comment
4
Maximum possible email length is254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.
– Sebastian Sulinski
Feb 3 '17 at 8:39
11
For Laravel 5.4, useIlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path
– webcoder
Mar 4 '17 at 4:05
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
4
4
Maximum possible email length is
254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.– Sebastian Sulinski
Feb 3 '17 at 8:39
Maximum possible email length is
254
so probably worth keeping this in mind, so I would probably validate the uniqueness using validator in that case.– Sebastian Sulinski
Feb 3 '17 at 8:39
11
11
For Laravel 5.4, use
IlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path– webcoder
Mar 4 '17 at 4:05
For Laravel 5.4, use
IlluminateDatabaseSchemaBuilder::defaultStringLength(191);
for correct function reference path– webcoder
Mar 4 '17 at 4:05
5
5
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
After making the configuration in the AppServiceProvider.php, this problem is still happening. I am just confused. Why? I restarted server, database and everything but still. Please help.
– Koushik Das
Mar 10 '17 at 16:54
3
3
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
You have to set the length of the indexed column according to the limit of 767 bytes. Be aware that VARCHAR may have 1, 2 or 4 bytes for each length unit. Example: utf8_mb4 (4 bytes) -> 767 / 4 = 191. Otherwise utf8_general_ci for VARCHAR(X) with X < 85 ( 1 byte ) = O(85) , or utf8_general_ci for VARCHAR(X) with X >= 86 ( 2 bytes ) -> 767 / 2 = 383. Consider also other columns lenght in multiple column indexes.
– Jack Degl'Innocenti
Jul 16 '17 at 14:37
1
1
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
You may also want to edit directly the length of the specific column in the migration files, over specifying a default length for all the string columns, as not all columns will need this constraint as they aren't in any index. $table->string('column_name',191);
– Jack Degl'Innocenti
Jul 16 '17 at 14:42
|
show 1 more comment
Update 1
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Update 2
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
Solution
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4
support for 😀 then start to fix 😂 your database configuration.
In Laravel config/database.php
define:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC
allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld]
# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1
For clients:
[mysql]
default-character-set=utf8mb4
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld
sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just indatabase.php
config file and it will impact local Laravel project. Be sure todelete
database before making changes and create it with new settings. You need to changemy.cnf
config file only for global server side changes (currently all new installations useutf8mb4
).
– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passingoptions={"row_format"="DYNAMIC"}
to your@Table
annotation.
– Albert221
Feb 20 '17 at 19:22
|
show 2 more comments
Update 1
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Update 2
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
Solution
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4
support for 😀 then start to fix 😂 your database configuration.
In Laravel config/database.php
define:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC
allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld]
# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1
For clients:
[mysql]
default-character-set=utf8mb4
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld
sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just indatabase.php
config file and it will impact local Laravel project. Be sure todelete
database before making changes and create it with new settings. You need to changemy.cnf
config file only for global server side changes (currently all new installations useutf8mb4
).
– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passingoptions={"row_format"="DYNAMIC"}
to your@Table
annotation.
– Albert221
Feb 20 '17 at 19:22
|
show 2 more comments
Update 1
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Update 2
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
Solution
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4
support for 😀 then start to fix 😂 your database configuration.
In Laravel config/database.php
define:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC
allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld]
# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1
For clients:
[mysql]
default-character-set=utf8mb4
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld
sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
Update 1
As of Laravel 5.4 those changes are no more needed.
Laravel 5.4 uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are upgrading your application from Laravel 5.3, you are not required to switch to this character set.
Update 2
Current production MariaDB versions DO NOT support this setting by default globally. It is implemented in MariaDB 10.2.2+ by default.
Solution
And if you intentionally want to use the correct future-default (starting from Laravel 5.4) UTF8 multi-byte utf8mb4
support for 😀 then start to fix 😂 your database configuration.
In Laravel config/database.php
define:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
DYNAMIC
allows to store long key indexes.
Server settings (by default included in MySQL 5.7.7+ / MariaDB 10.2.2+):
[mysqld]
# default character set and collation
collation-server = utf8mb4_unicode_ci
character-set-server = utf8mb4
# utf8mb4 long key index
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_format_max = barracuda
innodb_file_per_table = 1
For clients:
[mysql]
default-character-set=utf8mb4
And then STOP your MySQL/MariaDB server. After that START. Hot RESTART may not work.
sudo systemctl stop mysqld
sudo systemctl start mysqld
Now you have Laravel 5.x with UTF8 support.
edited Jan 27 '17 at 10:39
answered Sep 28 '16 at 14:18


scorerscorer
1,126410
1,126410
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just indatabase.php
config file and it will impact local Laravel project. Be sure todelete
database before making changes and create it with new settings. You need to changemy.cnf
config file only for global server side changes (currently all new installations useutf8mb4
).
– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passingoptions={"row_format"="DYNAMIC"}
to your@Table
annotation.
– Albert221
Feb 20 '17 at 19:22
|
show 2 more comments
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just indatabase.php
config file and it will impact local Laravel project. Be sure todelete
database before making changes and create it with new settings. You need to changemy.cnf
config file only for global server side changes (currently all new installations useutf8mb4
).
– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passingoptions={"row_format"="DYNAMIC"}
to your@Table
annotation.
– Albert221
Feb 20 '17 at 19:22
3
3
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
This might wok well enough with MySQL 5.5 (did not try to reconfigure). The 5.7 (probably also 5.6) worked without the need for any reconfiguration. The 5.7 was a default Community Server distribution with vanilla configuration.
– Pjotr
Oct 10 '16 at 13:43
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
I changed the engine in my database.php as you mentionned but it is still creating tables with row=compact which is causing a problem. I didn't fully understand, are you saying that it isn't enough to make this change in database.php and that it is also required to make the changes in the my.cnf file ?
– vesperknight
Jan 14 '17 at 10:15
It is enough to make changes just in
database.php
config file and it will impact local Laravel project. Be sure to delete
database before making changes and create it with new settings. You need to change my.cnf
config file only for global server side changes (currently all new installations use utf8mb4
).– scorer
Jan 14 '17 at 15:46
It is enough to make changes just in
database.php
config file and it will impact local Laravel project. Be sure to delete
database before making changes and create it with new settings. You need to change my.cnf
config file only for global server side changes (currently all new installations use utf8mb4
).– scorer
Jan 14 '17 at 15:46
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
Or - add another field, calculate the hash of the email, make the field unique, solve the problem forever, avoid fiddling with database initialization variables.
– N.B.
Jan 24 '17 at 22:00
If anybody is using Doctrine 2, you can set ROW_FORMAT by passing
options={"row_format"="DYNAMIC"}
to your @Table
annotation.– Albert221
Feb 20 '17 at 19:22
If anybody is using Doctrine 2, you can set ROW_FORMAT by passing
options={"row_format"="DYNAMIC"}
to your @Table
annotation.– Albert221
Feb 20 '17 at 19:22
|
show 2 more comments
If you're on or updated to Laravel 5.4 This worked for me;
Just 1 change. in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
As mentioned in the migrate guide https://laravel.com/docs/master/migrations#creating-indexes
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
add a comment |
If you're on or updated to Laravel 5.4 This worked for me;
Just 1 change. in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
As mentioned in the migrate guide https://laravel.com/docs/master/migrations#creating-indexes
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
add a comment |
If you're on or updated to Laravel 5.4 This worked for me;
Just 1 change. in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
As mentioned in the migrate guide https://laravel.com/docs/master/migrations#creating-indexes
If you're on or updated to Laravel 5.4 This worked for me;
Just 1 change. in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
As mentioned in the migrate guide https://laravel.com/docs/master/migrations#creating-indexes
answered Jan 27 '17 at 9:09
vartavarta
2,31111313
2,31111313
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
add a comment |
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
I did this on the migration itself.
– AmirMasoud
Mar 17 '17 at 8:13
4
4
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
This is (presumably) because each character takes up exactly 4 bytes, and the maximum key length is measured in bytes, not characters. So the key length will by 191 * 4 = 764 bytes, just a smidgen under the maximum 767 bytes the database will support. Solutions need explanations IMO if they are to contribute to the shared knowledge here, and not just provide "procedures". But a handy fix nonetheless.
– Jason
Jun 15 '17 at 10:07
add a comment |
If anyone else stumbles upon this answer like I did but for a different reason, you may check your Laravel DB charset/collation.
I was installing an application (Snipe-IT) and had configured the Laravel database config to use the following:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
Removing mb4
from both strings fixed the issue, although I believe Antonio's answer is the real solution to the problem.
add a comment |
If anyone else stumbles upon this answer like I did but for a different reason, you may check your Laravel DB charset/collation.
I was installing an application (Snipe-IT) and had configured the Laravel database config to use the following:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
Removing mb4
from both strings fixed the issue, although I believe Antonio's answer is the real solution to the problem.
add a comment |
If anyone else stumbles upon this answer like I did but for a different reason, you may check your Laravel DB charset/collation.
I was installing an application (Snipe-IT) and had configured the Laravel database config to use the following:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
Removing mb4
from both strings fixed the issue, although I believe Antonio's answer is the real solution to the problem.
If anyone else stumbles upon this answer like I did but for a different reason, you may check your Laravel DB charset/collation.
I was installing an application (Snipe-IT) and had configured the Laravel database config to use the following:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
Removing mb4
from both strings fixed the issue, although I believe Antonio's answer is the real solution to the problem.
answered Feb 23 '16 at 6:19
BrendanBrendan
4,14411935
4,14411935
add a comment |
add a comment |
This worked for me:
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
add a comment |
This worked for me:
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
add a comment |
This worked for me:
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
This worked for me:
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
answered Jan 27 '17 at 7:51
user3278647user3278647
359138
359138
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
add a comment |
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
This worked for me. I use Server version: 10.1.22-MariaDB - Source distribution
– Web Developer in Pune
Jan 18 '18 at 18:35
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
I also worked. I use Laravel version: 5.6
– ufuk
Jun 2 '18 at 7:23
add a comment |
Remove mb4 from charset and collation from config/database.php, then it will execute successfully.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
Remove mb4 from charset and collation from config/database.php, then it will execute successfully.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
Remove mb4 from charset and collation from config/database.php, then it will execute successfully.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
Remove mb4 from charset and collation from config/database.php, then it will execute successfully.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
answered Feb 9 '17 at 15:02


Ramv VRamv V
16516
16516
add a comment |
add a comment |
For laravel 5.4, simply edit file
AppProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
For laravel 5.4, simply edit file
AppProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
For laravel 5.4, simply edit file
AppProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
For laravel 5.4, simply edit file
AppProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
answered Jan 30 '17 at 17:16
VanndyVanndy
14115
14115
add a comment |
add a comment |
I have faced the same issue, and fixed it by adding the below two lines in my app/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
My file looks like below :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
......
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
add a comment |
I have faced the same issue, and fixed it by adding the below two lines in my app/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
My file looks like below :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
......
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
add a comment |
I have faced the same issue, and fixed it by adding the below two lines in my app/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
My file looks like below :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
......
I have faced the same issue, and fixed it by adding the below two lines in my app/database.php
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
My file looks like below :
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
......
answered Mar 16 '17 at 7:11


Muthu17Muthu17
858715
858715
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
add a comment |
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
If you installed new version in Laravel. Please remove 'mb4' from utf8mb4 & utf8mb4_unicode_ci & config/database.php
– Muthu17
May 8 '17 at 8:01
add a comment |
For laravel 5.6
This solution solve my problem
go to config/database.php
Find the code below
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Change this two field
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'
With This
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
add a comment |
For laravel 5.6
This solution solve my problem
go to config/database.php
Find the code below
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Change this two field
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'
With This
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
add a comment |
For laravel 5.6
This solution solve my problem
go to config/database.php
Find the code below
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Change this two field
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'
With This
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
For laravel 5.6
This solution solve my problem
go to config/database.php
Find the code below
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Change this two field
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci'
With This
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
answered May 29 '18 at 13:40


Avijit MandalAvijit Mandal
10115
10115
add a comment |
add a comment |
File: config/database.php
change the following
FROM ->
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
TO ->
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
add a comment |
File: config/database.php
change the following
FROM ->
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
TO ->
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
add a comment |
File: config/database.php
change the following
FROM ->
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
TO ->
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
File: config/database.php
change the following
FROM ->
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
TO ->
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
answered Jul 3 '18 at 14:43


Faizan NoorFaizan Noor
50978
50978
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
add a comment |
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
1
1
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.
– Roshana Pitigala
Jul 3 '18 at 16:47
add a comment |
In file config/database.php where :
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Change this line to this :
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
In file config/database.php where :
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Change this line to this :
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
add a comment |
In file config/database.php where :
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Change this line to this :
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
In file config/database.php where :
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Change this line to this :
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
answered Oct 23 '17 at 13:14
AdrianAdrian
6515
6515
add a comment |
add a comment |
i had same problem and i am using a wamp
Solution :
Open file :
config/database.php
'engine' => null, => 'engine' => 'InnoDB',
Thanks
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
add a comment |
i had same problem and i am using a wamp
Solution :
Open file :
config/database.php
'engine' => null, => 'engine' => 'InnoDB',
Thanks
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
add a comment |
i had same problem and i am using a wamp
Solution :
Open file :
config/database.php
'engine' => null, => 'engine' => 'InnoDB',
Thanks
i had same problem and i am using a wamp
Solution :
Open file :
config/database.php
'engine' => null, => 'engine' => 'InnoDB',
Thanks
answered Feb 23 '17 at 6:46
PurveshPurvesh
399311
399311
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
add a comment |
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
None of the previous answers worked for me, but this one worked like a charm! And it makes perfect sense, I believe in previous versions of Laravel DB engine was set to InnoDB by default so we didn't encounter these errors previously.
– Sasa Blagojevic
Aug 31 '17 at 15:07
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
yes needed to do a couple of the other answers and this as well.
– Andrew
Oct 9 '17 at 16:13
add a comment |
I added to the migration itself
Schema::defaultStringLength(191);
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
yes, I know I need to consider it on every migration but I would rather that than have it tucked away in some completely unrelated service provider
add a comment |
I added to the migration itself
Schema::defaultStringLength(191);
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
yes, I know I need to consider it on every migration but I would rather that than have it tucked away in some completely unrelated service provider
add a comment |
I added to the migration itself
Schema::defaultStringLength(191);
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
yes, I know I need to consider it on every migration but I would rather that than have it tucked away in some completely unrelated service provider
I added to the migration itself
Schema::defaultStringLength(191);
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
yes, I know I need to consider it on every migration but I would rather that than have it tucked away in some completely unrelated service provider
answered Jun 3 '17 at 18:32


Manoj ThapliyalManoj Thapliyal
46557
46557
add a comment |
add a comment |
for laravel 5.7 write these code in appserviceprovider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
for laravel 5.7 write these code in appserviceprovider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
for laravel 5.7 write these code in appserviceprovider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
for laravel 5.7 write these code in appserviceprovider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
answered Oct 25 '18 at 9:25
ahmed farghalyahmed farghaly
312
312
add a comment |
add a comment |
It's because Laravel 5.4 uses utf8mb4 which supports storing emojis.
Add this in your appProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
and you should be good to go.
add a comment |
It's because Laravel 5.4 uses utf8mb4 which supports storing emojis.
Add this in your appProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
and you should be good to go.
add a comment |
It's because Laravel 5.4 uses utf8mb4 which supports storing emojis.
Add this in your appProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
and you should be good to go.
It's because Laravel 5.4 uses utf8mb4 which supports storing emojis.
Add this in your appProvidersAppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
and you should be good to go.
answered Oct 7 '17 at 16:28


Irteza AsadIrteza Asad
17123
17123
add a comment |
add a comment |
If you're on or updated to Laravel 5.4 and latest version it works;
Just 1 change in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
add a comment |
If you're on or updated to Laravel 5.4 and latest version it works;
Just 1 change in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
add a comment |
If you're on or updated to Laravel 5.4 and latest version it works;
Just 1 change in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
If you're on or updated to Laravel 5.4 and latest version it works;
Just 1 change in AppServiceProvider.php
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
edited Dec 16 '17 at 11:53


Thomas Fritsch
5,456122135
5,456122135
answered Dec 16 '17 at 11:33


Umar TariqUmar Tariq
48269
48269
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
add a comment |
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
This also work for me for laravel 5.5
– Yusuf
Jan 7 '18 at 21:28
add a comment |
If someone having this problem even after doing, above mentioned changes. For an example, in my case I did below changes,
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
But it wouldn't work right away for two reasons. One is if you are using lumen instead of laravel, you may have to uncomment this line in your app.php file first.
$app->register(AppProvidersAppServiceProvider::class);
And then you have to create the migration script again with the artisan command,
php artisan make:migration <your_table_name>
Since now only the changes you made to ServiceProvider will work.
add a comment |
If someone having this problem even after doing, above mentioned changes. For an example, in my case I did below changes,
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
But it wouldn't work right away for two reasons. One is if you are using lumen instead of laravel, you may have to uncomment this line in your app.php file first.
$app->register(AppProvidersAppServiceProvider::class);
And then you have to create the migration script again with the artisan command,
php artisan make:migration <your_table_name>
Since now only the changes you made to ServiceProvider will work.
add a comment |
If someone having this problem even after doing, above mentioned changes. For an example, in my case I did below changes,
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
But it wouldn't work right away for two reasons. One is if you are using lumen instead of laravel, you may have to uncomment this line in your app.php file first.
$app->register(AppProvidersAppServiceProvider::class);
And then you have to create the migration script again with the artisan command,
php artisan make:migration <your_table_name>
Since now only the changes you made to ServiceProvider will work.
If someone having this problem even after doing, above mentioned changes. For an example, in my case I did below changes,
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesSchema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
But it wouldn't work right away for two reasons. One is if you are using lumen instead of laravel, you may have to uncomment this line in your app.php file first.
$app->register(AppProvidersAppServiceProvider::class);
And then you have to create the migration script again with the artisan command,
php artisan make:migration <your_table_name>
Since now only the changes you made to ServiceProvider will work.
answered Oct 9 '18 at 9:09
dilantha111dilantha111
326311
326311
add a comment |
add a comment |
For Laravel >= 5.6 users
Open AppServiceProvider.php
file
Use the following class
use IlluminateSupportFacadesSchema;
Then inside boot
method add the following line
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
For Laravel >= 5.6 users
Open AppServiceProvider.php
file
Use the following class
use IlluminateSupportFacadesSchema;
Then inside boot
method add the following line
public function boot()
{
Schema::defaultStringLength(191);
}
add a comment |
For Laravel >= 5.6 users
Open AppServiceProvider.php
file
Use the following class
use IlluminateSupportFacadesSchema;
Then inside boot
method add the following line
public function boot()
{
Schema::defaultStringLength(191);
}
For Laravel >= 5.6 users
Open AppServiceProvider.php
file
Use the following class
use IlluminateSupportFacadesSchema;
Then inside boot
method add the following line
public function boot()
{
Schema::defaultStringLength(191);
}
edited Dec 18 '18 at 2:29
answered Apr 13 '18 at 14:13


Wael AssafWael Assaf
545513
545513
add a comment |
add a comment |
Change charset to from 'utf8mb4' to 'utf8' and
collation to 'utf8mb4_unicode_ci' to 'utf8_unicode_ci'
in config/database.php file
It worked for me.
add a comment |
Change charset to from 'utf8mb4' to 'utf8' and
collation to 'utf8mb4_unicode_ci' to 'utf8_unicode_ci'
in config/database.php file
It worked for me.
add a comment |
Change charset to from 'utf8mb4' to 'utf8' and
collation to 'utf8mb4_unicode_ci' to 'utf8_unicode_ci'
in config/database.php file
It worked for me.
Change charset to from 'utf8mb4' to 'utf8' and
collation to 'utf8mb4_unicode_ci' to 'utf8_unicode_ci'
in config/database.php file
It worked for me.
answered Jul 23 '17 at 14:43
Chetan GodhaniChetan Godhani
112
112
add a comment |
add a comment |
Laravel uses the utf8mb4
character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength
method within your AppServiceProvider
:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
You can check out of
https://laravel-news.com/laravel-5-4-key-too-long-error
https://laravel.com/docs/5.5/migrations#indexes
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
add a comment |
Laravel uses the utf8mb4
character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength
method within your AppServiceProvider
:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
You can check out of
https://laravel-news.com/laravel-5-4-key-too-long-error
https://laravel.com/docs/5.5/migrations#indexes
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
add a comment |
Laravel uses the utf8mb4
character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength
method within your AppServiceProvider
:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
You can check out of
https://laravel-news.com/laravel-5-4-key-too-long-error
https://laravel.com/docs/5.5/migrations#indexes
Laravel uses the utf8mb4
character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength
method within your AppServiceProvider
:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
You can check out of
https://laravel-news.com/laravel-5-4-key-too-long-error
https://laravel.com/docs/5.5/migrations#indexes
answered Aug 30 '17 at 18:01


Barakat TurkiBarakat Turki
1541213
1541213
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
add a comment |
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
thanks, works for me. mamp mysql with laravel 5.6.23
– bluesky
Jun 4 '18 at 12:38
add a comment |
I'd like to point that something that i missed ...
I'm new at Laravel, and i didn't copy the "use Illuminate....." because i really didn'at paid atention, because right above the function boot you alread have a use Statement.
Hope that helps anyone
**use IlluminateSupportFacadesSchema;**
public function boot()
{
Schema::defaultStringLength(191);
}
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
add a comment |
I'd like to point that something that i missed ...
I'm new at Laravel, and i didn't copy the "use Illuminate....." because i really didn'at paid atention, because right above the function boot you alread have a use Statement.
Hope that helps anyone
**use IlluminateSupportFacadesSchema;**
public function boot()
{
Schema::defaultStringLength(191);
}
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
add a comment |
I'd like to point that something that i missed ...
I'm new at Laravel, and i didn't copy the "use Illuminate....." because i really didn'at paid atention, because right above the function boot you alread have a use Statement.
Hope that helps anyone
**use IlluminateSupportFacadesSchema;**
public function boot()
{
Schema::defaultStringLength(191);
}
I'd like to point that something that i missed ...
I'm new at Laravel, and i didn't copy the "use Illuminate....." because i really didn'at paid atention, because right above the function boot you alread have a use Statement.
Hope that helps anyone
**use IlluminateSupportFacadesSchema;**
public function boot()
{
Schema::defaultStringLength(191);
}
answered Mar 20 '18 at 14:15
Samuel Aiala FerreiraSamuel Aiala Ferreira
18615
18615
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
add a comment |
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
You can also just prefix any Facade with
– Ohgodwhy
May 30 '18 at 0:43
add a comment |
I had a problem, change the configuration of the 'config / database'
file 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
keeping the same pattern in the database.
I then gave the command
php artisan migrate
add a comment |
I had a problem, change the configuration of the 'config / database'
file 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
keeping the same pattern in the database.
I then gave the command
php artisan migrate
add a comment |
I had a problem, change the configuration of the 'config / database'
file 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
keeping the same pattern in the database.
I then gave the command
php artisan migrate
I had a problem, change the configuration of the 'config / database'
file 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
keeping the same pattern in the database.
I then gave the command
php artisan migrate
answered Jul 25 '18 at 2:54


Emerson Santana CunhaEmerson Santana Cunha
111
111
add a comment |
add a comment |
In 24 october 2016 Taylor Otwell the Author of Laravel announced on is Twitter
"utf8mb4" will be the default MySQL character set in Laravel 5.4 for better emoji support. 🙌 Taylor Otwell Twitter Post
which before version 5.4 the character set was utf8
During this century many web app, include chat or some kind platform to allow their users to converses, and many people like to use emoji or smiley. and this are some kind of super characters that require more spaces to be store and that is only possible using utf8mb4
as the charset. That is the reason why they migrate to utf8mb4
just for space purpose.
if you look up in the IlluminateDatabaseSchemaBuilder
class you will see that the $defaultStringLength
is set to 255, and to modify that you can procede through the Schema
Facade and call the defaultStringLength
method and pass the new length.
to perform that change call that method within your AppServiceProvider
class which is under the appproviders subdirectory like this
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// all other code ...
Schema::defaultStringLength(191);
}
// and all other code goes here
}
I will suggest to use 191 as the value just because MySQL support 767 bytes, and because 767 / 4
which is the number of byte take by each multibyte character you will get 191
.
You can learn more here
The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
Limits on Table Column Count and Row Size
This is the only answer that explains the191
magic number.
– Illya Moskvin
Mar 5 at 17:50
add a comment |
In 24 october 2016 Taylor Otwell the Author of Laravel announced on is Twitter
"utf8mb4" will be the default MySQL character set in Laravel 5.4 for better emoji support. 🙌 Taylor Otwell Twitter Post
which before version 5.4 the character set was utf8
During this century many web app, include chat or some kind platform to allow their users to converses, and many people like to use emoji or smiley. and this are some kind of super characters that require more spaces to be store and that is only possible using utf8mb4
as the charset. That is the reason why they migrate to utf8mb4
just for space purpose.
if you look up in the IlluminateDatabaseSchemaBuilder
class you will see that the $defaultStringLength
is set to 255, and to modify that you can procede through the Schema
Facade and call the defaultStringLength
method and pass the new length.
to perform that change call that method within your AppServiceProvider
class which is under the appproviders subdirectory like this
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// all other code ...
Schema::defaultStringLength(191);
}
// and all other code goes here
}
I will suggest to use 191 as the value just because MySQL support 767 bytes, and because 767 / 4
which is the number of byte take by each multibyte character you will get 191
.
You can learn more here
The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
Limits on Table Column Count and Row Size
This is the only answer that explains the191
magic number.
– Illya Moskvin
Mar 5 at 17:50
add a comment |
In 24 october 2016 Taylor Otwell the Author of Laravel announced on is Twitter
"utf8mb4" will be the default MySQL character set in Laravel 5.4 for better emoji support. 🙌 Taylor Otwell Twitter Post
which before version 5.4 the character set was utf8
During this century many web app, include chat or some kind platform to allow their users to converses, and many people like to use emoji or smiley. and this are some kind of super characters that require more spaces to be store and that is only possible using utf8mb4
as the charset. That is the reason why they migrate to utf8mb4
just for space purpose.
if you look up in the IlluminateDatabaseSchemaBuilder
class you will see that the $defaultStringLength
is set to 255, and to modify that you can procede through the Schema
Facade and call the defaultStringLength
method and pass the new length.
to perform that change call that method within your AppServiceProvider
class which is under the appproviders subdirectory like this
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// all other code ...
Schema::defaultStringLength(191);
}
// and all other code goes here
}
I will suggest to use 191 as the value just because MySQL support 767 bytes, and because 767 / 4
which is the number of byte take by each multibyte character you will get 191
.
You can learn more here
The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
Limits on Table Column Count and Row Size
In 24 october 2016 Taylor Otwell the Author of Laravel announced on is Twitter
"utf8mb4" will be the default MySQL character set in Laravel 5.4 for better emoji support. 🙌 Taylor Otwell Twitter Post
which before version 5.4 the character set was utf8
During this century many web app, include chat or some kind platform to allow their users to converses, and many people like to use emoji or smiley. and this are some kind of super characters that require more spaces to be store and that is only possible using utf8mb4
as the charset. That is the reason why they migrate to utf8mb4
just for space purpose.
if you look up in the IlluminateDatabaseSchemaBuilder
class you will see that the $defaultStringLength
is set to 255, and to modify that you can procede through the Schema
Facade and call the defaultStringLength
method and pass the new length.
to perform that change call that method within your AppServiceProvider
class which is under the appproviders subdirectory like this
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// all other code ...
Schema::defaultStringLength(191);
}
// and all other code goes here
}
I will suggest to use 191 as the value just because MySQL support 767 bytes, and because 767 / 4
which is the number of byte take by each multibyte character you will get 191
.
You can learn more here
The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
Limits on Table Column Count and Row Size
answered Sep 20 '18 at 12:59


Yves KipondoYves Kipondo
1,451515
1,451515
This is the only answer that explains the191
magic number.
– Illya Moskvin
Mar 5 at 17:50
add a comment |
This is the only answer that explains the191
magic number.
– Illya Moskvin
Mar 5 at 17:50
This is the only answer that explains the
191
magic number.– Illya Moskvin
Mar 5 at 17:50
This is the only answer that explains the
191
magic number.– Illya Moskvin
Mar 5 at 17:50
add a comment |
You will not have this problem if you're using MySQL 5.7.7+ or MariaDB 10.2.2+.
To update MariaDB on your Mac using Brew first unlink the current one:
brew unlink mariadb
and then install a dev one using brew install mariadb --devel
After installation is done stop/start the service running:
brew services stop mariadb
brew services start mariadb
Current dev version is 10.2.3. After the installation is finished you won't have to worry about this anymore and you can use utf8mb4 (that is now a default in Laravel 5.4) without switching back to utf8 nor editing AppServiceProvider as proposed in the Laravel documentation: https://laravel.com/docs/master/releases#laravel-5.4 (scroll down to: Migration Default String Length)
add a comment |
You will not have this problem if you're using MySQL 5.7.7+ or MariaDB 10.2.2+.
To update MariaDB on your Mac using Brew first unlink the current one:
brew unlink mariadb
and then install a dev one using brew install mariadb --devel
After installation is done stop/start the service running:
brew services stop mariadb
brew services start mariadb
Current dev version is 10.2.3. After the installation is finished you won't have to worry about this anymore and you can use utf8mb4 (that is now a default in Laravel 5.4) without switching back to utf8 nor editing AppServiceProvider as proposed in the Laravel documentation: https://laravel.com/docs/master/releases#laravel-5.4 (scroll down to: Migration Default String Length)
add a comment |
You will not have this problem if you're using MySQL 5.7.7+ or MariaDB 10.2.2+.
To update MariaDB on your Mac using Brew first unlink the current one:
brew unlink mariadb
and then install a dev one using brew install mariadb --devel
After installation is done stop/start the service running:
brew services stop mariadb
brew services start mariadb
Current dev version is 10.2.3. After the installation is finished you won't have to worry about this anymore and you can use utf8mb4 (that is now a default in Laravel 5.4) without switching back to utf8 nor editing AppServiceProvider as proposed in the Laravel documentation: https://laravel.com/docs/master/releases#laravel-5.4 (scroll down to: Migration Default String Length)
You will not have this problem if you're using MySQL 5.7.7+ or MariaDB 10.2.2+.
To update MariaDB on your Mac using Brew first unlink the current one:
brew unlink mariadb
and then install a dev one using brew install mariadb --devel
After installation is done stop/start the service running:
brew services stop mariadb
brew services start mariadb
Current dev version is 10.2.3. After the installation is finished you won't have to worry about this anymore and you can use utf8mb4 (that is now a default in Laravel 5.4) without switching back to utf8 nor editing AppServiceProvider as proposed in the Laravel documentation: https://laravel.com/docs/master/releases#laravel-5.4 (scroll down to: Migration Default String Length)
answered Jan 27 '17 at 2:19


Richard DawsonRichard Dawson
1
1
add a comment |
add a comment |
Just installed MariaDB 10.2.4 RC, fired up new blank Laravel 5.4 project and default migration (varchar(255) columns) works.
No need to change DB conf and Laravael config/database.php
. Thus just as @scorer noted about default behaviour for 10.2.2+.
add a comment |
Just installed MariaDB 10.2.4 RC, fired up new blank Laravel 5.4 project and default migration (varchar(255) columns) works.
No need to change DB conf and Laravael config/database.php
. Thus just as @scorer noted about default behaviour for 10.2.2+.
add a comment |
Just installed MariaDB 10.2.4 RC, fired up new blank Laravel 5.4 project and default migration (varchar(255) columns) works.
No need to change DB conf and Laravael config/database.php
. Thus just as @scorer noted about default behaviour for 10.2.2+.
Just installed MariaDB 10.2.4 RC, fired up new blank Laravel 5.4 project and default migration (varchar(255) columns) works.
No need to change DB conf and Laravael config/database.php
. Thus just as @scorer noted about default behaviour for 10.2.2+.
answered Mar 5 '17 at 15:07


krokokroko
394
394
add a comment |
add a comment |
All was well described in the others Anwser
you can see more details in the link bellow (search with key 'Index Lengths & MySQL / MariaDB")
https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what this answer is about! the thing is even with doing the above you will like get another error (that's when you like launch php artisan migrate
command and because of the problem of the length, the operation like stuck in the middle. solution is bellow, and the user table is like created without the rest or not totally correctly)
we need to roll back. the default roll back will not do. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.
we can do it using tinker as in bellow:
L:todos> php artisan tinker
Psy Shell v0.8.15 (PHP 7.1.10 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
I myself had a problem with users table.
after that your good to go
php artisan migrate:rollback
php artisan migrate
add a comment |
All was well described in the others Anwser
you can see more details in the link bellow (search with key 'Index Lengths & MySQL / MariaDB")
https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what this answer is about! the thing is even with doing the above you will like get another error (that's when you like launch php artisan migrate
command and because of the problem of the length, the operation like stuck in the middle. solution is bellow, and the user table is like created without the rest or not totally correctly)
we need to roll back. the default roll back will not do. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.
we can do it using tinker as in bellow:
L:todos> php artisan tinker
Psy Shell v0.8.15 (PHP 7.1.10 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
I myself had a problem with users table.
after that your good to go
php artisan migrate:rollback
php artisan migrate
add a comment |
All was well described in the others Anwser
you can see more details in the link bellow (search with key 'Index Lengths & MySQL / MariaDB")
https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what this answer is about! the thing is even with doing the above you will like get another error (that's when you like launch php artisan migrate
command and because of the problem of the length, the operation like stuck in the middle. solution is bellow, and the user table is like created without the rest or not totally correctly)
we need to roll back. the default roll back will not do. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.
we can do it using tinker as in bellow:
L:todos> php artisan tinker
Psy Shell v0.8.15 (PHP 7.1.10 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
I myself had a problem with users table.
after that your good to go
php artisan migrate:rollback
php artisan migrate
All was well described in the others Anwser
you can see more details in the link bellow (search with key 'Index Lengths & MySQL / MariaDB")
https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what this answer is about! the thing is even with doing the above you will like get another error (that's when you like launch php artisan migrate
command and because of the problem of the length, the operation like stuck in the middle. solution is bellow, and the user table is like created without the rest or not totally correctly)
we need to roll back. the default roll back will not do. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.
we can do it using tinker as in bellow:
L:todos> php artisan tinker
Psy Shell v0.8.15 (PHP 7.1.10 — cli) by Justin Hileman
>>> Schema::drop('users')
=> null
I myself had a problem with users table.
after that your good to go
php artisan migrate:rollback
php artisan migrate
edited Jan 17 '18 at 20:54
answered Jan 17 '18 at 20:44


Mohamed AllalMohamed Allal
2,4491621
2,4491621
add a comment |
add a comment |
Set database engine InnoDB:
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
add a comment |
Set database engine InnoDB:
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
add a comment |
Set database engine InnoDB:
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Set database engine InnoDB:
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
edited Feb 3 '18 at 13:11
WebDevBooster
8,66873044
8,66873044
answered Feb 3 '18 at 12:50


Harshad ValaHarshad Vala
111
111
add a comment |
add a comment |
If you have tried every other answer and they have not worked, you can drop all tables from the database and then execute the migrate command all at once using this command:
php artisan migrate:fresh
add a comment |
If you have tried every other answer and they have not worked, you can drop all tables from the database and then execute the migrate command all at once using this command:
php artisan migrate:fresh
add a comment |
If you have tried every other answer and they have not worked, you can drop all tables from the database and then execute the migrate command all at once using this command:
php artisan migrate:fresh
If you have tried every other answer and they have not worked, you can drop all tables from the database and then execute the migrate command all at once using this command:
php artisan migrate:fresh
edited Jun 24 '18 at 20:23


Grant Miller
6,231133257
6,231133257
answered Jun 24 '18 at 19:06
TreasureTreasure
646
646
add a comment |
add a comment |
If you are seeing this error then definitely you need to make following changes on
AppServiceProvider.php
file -> which can be found inside app->providers:
changes to be made
use IlluminateSupportFacadesSchema; //see if you have this class if not add it.
public function boot()
{
Schema::defaultStringLength(191); //make sure you add this line
}
this should solve your problem for more you can see the Laravel news regarding this issue.
https://laravel-news.com/laravel-5-4-key-too-long-error
add a comment |
If you are seeing this error then definitely you need to make following changes on
AppServiceProvider.php
file -> which can be found inside app->providers:
changes to be made
use IlluminateSupportFacadesSchema; //see if you have this class if not add it.
public function boot()
{
Schema::defaultStringLength(191); //make sure you add this line
}
this should solve your problem for more you can see the Laravel news regarding this issue.
https://laravel-news.com/laravel-5-4-key-too-long-error
add a comment |
If you are seeing this error then definitely you need to make following changes on
AppServiceProvider.php
file -> which can be found inside app->providers:
changes to be made
use IlluminateSupportFacadesSchema; //see if you have this class if not add it.
public function boot()
{
Schema::defaultStringLength(191); //make sure you add this line
}
this should solve your problem for more you can see the Laravel news regarding this issue.
https://laravel-news.com/laravel-5-4-key-too-long-error
If you are seeing this error then definitely you need to make following changes on
AppServiceProvider.php
file -> which can be found inside app->providers:
changes to be made
use IlluminateSupportFacadesSchema; //see if you have this class if not add it.
public function boot()
{
Schema::defaultStringLength(191); //make sure you add this line
}
this should solve your problem for more you can see the Laravel news regarding this issue.
https://laravel-news.com/laravel-5-4-key-too-long-error
edited Jul 21 '18 at 6:28


Alien
5,33231127
5,33231127
answered Jul 21 '18 at 6:03


Sandesh PoudelSandesh Poudel
4810
4810
add a comment |
add a comment |
SOLUTION:
First change the defaultStringLength to 191, in the appProvidersAppServiceProvider.php:
public function boot()
{
Schema::defaultStringLength(191);
}
Then, change the charset and collation values as follows, in configdatabase.php:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
(link to know about MariaDB charset)
add a comment |
SOLUTION:
First change the defaultStringLength to 191, in the appProvidersAppServiceProvider.php:
public function boot()
{
Schema::defaultStringLength(191);
}
Then, change the charset and collation values as follows, in configdatabase.php:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
(link to know about MariaDB charset)
add a comment |
SOLUTION:
First change the defaultStringLength to 191, in the appProvidersAppServiceProvider.php:
public function boot()
{
Schema::defaultStringLength(191);
}
Then, change the charset and collation values as follows, in configdatabase.php:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
(link to know about MariaDB charset)
SOLUTION:
First change the defaultStringLength to 191, in the appProvidersAppServiceProvider.php:
public function boot()
{
Schema::defaultStringLength(191);
}
Then, change the charset and collation values as follows, in configdatabase.php:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
(link to know about MariaDB charset)
answered Jan 19 at 9:10
Naveen Kumar VNaveen Kumar V
598724
598724
add a comment |
add a comment |
1 2
next
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23786359%2flaravel-migration-unique-key-is-too-long-even-if-specified%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why are you using 320 chars for e-mail? This might be your problem.
– Antonio Carlos Ribeiro
May 21 '14 at 14:37
1
That was indeed the problem, no idea why. But yes, you are right, I don't know why I specified the char length for each field. Have removed these limits
– harryg
May 21 '14 at 14:41
It's funny how no one suggested using fixed-length field that contains hash of the email and voila - problem solved forever, for any framework and for any relational database. Because that's how we guarantee uniqueness - using a fixed-number representation of variable-length input, given the fact that number range is sufficiently large (and for sha1 / sha256 it is).
– N.B.
Jan 24 '17 at 21:59
1
laravel-news.com/laravel-5-4-key-too-long-error may get help
– matinict
Aug 9 '17 at 9:09
1
Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
– alishaukat
Aug 12 '17 at 10:40