Last active
October 29, 2021 08:14
-
-
Save yavgel85/8d7affd6cc2cc942f7d7be19a2b08e2e to your computer and use it in GitHub Desktop.
Specified key was too long #laravel #sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes | |
use Illuminate\Support\Facades\Schema; | |
public function boot() | |
{ | |
Schema::defaultStringLength(191); | |
} | |
# OR THIS WAY | |
# Laravel's Blueprint $table accepts a raw statement, so you can define it this way | |
Schema::table('table_name', function (Blueprint $table) { | |
$table->index([DB::raw('field_name(50)')], 'index_name'); | |
}); | |
# index_name is optional as Laravel neatly prefixes table name to field name, so it becomes table_name_field_name | |
# As to why this error occurs and finding the ideal index size, this is a great answer on Stackoverflow | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment