I'm trying to test a migration rollback after changing a column type and setting the index.
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('attachments', function(Blueprint $table) {
$table->dropIndex('attachment_id');
$table->text('attachment_id')->nullable()->change();
});
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('attachments', function(Blueprint $table) {
$table->unsignedBigInteger('attachment_id')->nullable()->change();
$table->index('attachment_id');
});
}
The migration runs fine and assigns the index. But when I run the rollback I run into the following error:
SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'attachment_id' used in key specification without a key length (SQL: ALTER TABLE attachments CHANGE attachment_id attachment_id TEXT DEFAULT NULL)
This table was originally set up incorrectly (without an index and without the correct column type). I'm trying to update this but I also want to make sure if any issues occur in production due to the change it can be rolled back quickly.
How are you meant to get around this? The index is already meant to be dropped?
I've tried changing the order of operations and also running separate Schema functions. Also tried changing it to a string instead of text with a set length and no luck.
The below doesn't work:
public function down()
{
Schema::table('attachments', function(Blueprint $table) {
$table->dropIndex('attachment_id');
});
Schema::table('attachments', function(Blueprint $table) {
$table->string('attachment_id', 255)->change();
});
}
public function down()
{
Schema::table('attachments', function(Blueprint $table) {
$table->dropIndex('attachment_id');
$table->string('attachment_id', 255)->change();
});
}
public function down()
{
Schema::table('attachments', function(Blueprint $table) {
$table->string('attachment_id', 255)->change();
$table->dropIndex('attachment_id');
});
}