php artisan migrate:fresh
php artisan migrate:install
Schema::table('table_name', function (Blueprint $table)
{
$table->index([DB::raw('field_name(50)')], 'index_name');
});
Laravel's Blueprint $table
accepts a raw statement. Definingindex_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.
Note: This is a solution to the error, specified key was too long; max key length is 3072 bytes
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
class AlterRenameTableOldNameToNewName extends Migration
{
public function up()
{
Schema::rename('old_name', 'new_name');
}
public function down() {}
}
For example, if in a past time a migration was ran but by accident data in the table was edited or completely deleted (truncated), then re-running just that specific migration file can be helpful and straightforward.
To do so, run the following command on terminal within the /application/ folder:
php artisan migrate:refresh --path=/database/migrations/2020_01_10_200000_create_example_table.php