The issue I run into is that when I run my database migrations I get an error when the charset is utf8mb4
due to this line and some other indexes:
$table->string('taggable_type', 255)->index();
So, I thought that if I can modify the charset that is being used to utf8 in config/database.php by checking which MySQL version is used, the issue can be solved/worked around.
I was thinking about doing a raw query like:
\Illuminate\Support\Facades\DB::raw('SHOW VARIABLES LIKE "%version%"');
inside config/database.php
. Now that error I receive is that
A facade root has not been set.
How can I solve this issue?
Yes, I have tried setting Schema::defaultStringLength(191);
inside the boot method of my AppServiceProvider and I have also tried 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC'
, but I still receive that the specified key is too long which I believe might be due to MySQL 5.5 I believe.
Any help as to how I can check the MySQL version inside a config file or a hint to a different approach would be highly appreciated.
The following is available since 5.5.14.
innodb_file_format=Barracuda
innodb_large_prefix=1
This also requires the 'engine' => 'innodb row_format=dynamic'
which you've mentioned that you're already using. I am repeating it here for completeness.
Newer mysql versions (>=5.7.9) has a innodb_default_row_format=dynamic
which can be used instead of the config change.
Since there's a real difference between utf8
and utf8mb4
(the former cannot represent a whole host of possible Unicode characters), you need to decide on whether you require utf8mb4
or not. If you don't, and you want the option to support older MySQL versions, then simply settle on using utf8
. If on the other hand you do require utf8mb4
to guarantee the correct working of your app, then insist on using utf8mb4
and ensure that the databases you're running on support it.