Published 4 months ago by Demers94
I've just upgraded to Laravel 5.4 and created my first project with it. When I first try to migrate the database, I get this error :
SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table
I can fix this by going in the migration for the
users table, and manually specifying the max-length of the email field, like so :
If I run
php artisan migrate again, it will work for the
users table, but will fail for the password reset table. I have to do the same thing for the email field in that migration.
Has anyone else encountered this issue? It was working fine before with 5.3.
I'm running Windows 10 and using HeidiSQL to create my database, like I've always used before.
The solution was to add this line in the boot() method of the AppServiceProvider :
(don't forget to import the namespace)
You can read about this in the migrations' documentation : https://github.com/laravel/docs/blob/5.4/migrations.md#index-lengths--mysql
@k32y I tried your solution, but then I get a new error in another of my tables, which says you cannot add a foreign key constraint. SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
Is there another engine option for MySQL which can solve the UTF8MB4 issue as well as allow FK constraints in the standard way, or can MyISAM handle it with some other small change? I'm running MySQL 5.7.11 locally, but the application will eventually run in the cloud and needs to be robust for any MySQL db.
Thank you for any help.
https://dev.mysql.com/doc/refman/5.7/en/innodb-foreign-key-constraints.html "InnoDB permits a foreign key to reference any index column or group of columns. However, in the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order. InnoDB does not currently support foreign keys for tables with user-defined partitioning. This means that no user-partitioned InnoDB table may contain foreign key references or columns referenced by foreign keys."
@elocke2017 Your problem is not with InnoDB. MyISAM does not support foreign key and therefore won't work. The problem is more likely one of the following: