Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Database migrations in fresh install do not work #17530

Closed
drn5910 opened this issue Jan 25, 2017 · 6 comments
Closed

[5.4] Database migrations in fresh install do not work #17530

drn5910 opened this issue Jan 25, 2017 · 6 comments

Comments

@drn5910
Copy link

drn5910 commented Jan 25, 2017

  • Laravel Version: 5.4.0
  • PHP Version: 5.6.14
  • Database Driver & Version: MariaDB (MySQL) 10.1.8

Description:

I freshly installed Laravel 5.4 and ran the commands to generate the sessions, failed_jobs, notifications tables in the database.

The following migrations all fail to run due to the recent change from UTF8 charsetto utf8mb4. This is due to the column length on these migrations not being defined by default in a new install.

  • create_users
  • password_resets
  • notifications
  • sessions

The string call in these migrations doesn't specify a length, so it uses Builder::$defaultStringLength which is currently still set to 255 causing this error and making migrations not migratable from the start without changing this value via defaultStringLength() method on the Builder class.

The following errors are produced when running migrations:

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

Steps To Reproduce:

  1. Install laravel 5.4
  2. Set up configuration for database connection (no changes needed otherwise)
  3. Try to migrate
  4. See the failure

Thank you.

@coolynx
Copy link

coolynx commented Jan 25, 2017

Can you add another line in config/database.php file:

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

And try again.

@drn5910
Copy link
Author

drn5910 commented Jan 25, 2017

Apologies if I was not clear - this isn't something I need a solution to for myself, but something that is broken within the framework without first changing something.

If the above fix is what is recommended then it should be in the configuration by default for new installs. However it would make more sense for something that uses utf8mb4 by default to change the default string length to 191 instead of the 255 it currently has.

@coolynx
Copy link

coolynx commented Jan 25, 2017

You did not provide the error message. So, my guess was based on my experience with similar case.

If this solution worked then there are two things to consider:

  1. Laravel 5.4 works out of box
  2. Laravel 5.4 does not work out of box in specific conditions, i.e., when used with older MySQL/MariaDB versions and configurations. In those conditions you should specify this extra line.

And yes - it probably should be mentioned in documentation.

But before that we should find out if this is the case.

@antonkomarev
Copy link
Contributor

Add this to your AppServiceProvider if you have MySQL lower than 5.7.7:

use Illuminate\Support\Facades\Schema;

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

@fernandobandeira
Copy link
Contributor

fernandobandeira commented Jan 25, 2017

An alternative solution for you is enabling innodb_large_prefix on your MariaDB, this way you won't need to touch the code, also it is working out of the box on MySQL 5.7...

@drn5910
Copy link
Author

drn5910 commented Jan 25, 2017

Thank you all, I see the version of MariaDB I am on is slightly behind the one where the defaults have changed (10.2.2). My file format for databases is still on Antelope so I had to adjust it to allow Barracuda, and turn on innodb_large_prefix. Apologies for the misunderstanding :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants