How can I rollback a specific batch from the migration? I created a column in a previous batch and I want to drop only that column without dropping all batched after that. Is there an official way to do it?
I know that I can just altering the batch number to the last batch and than use migrate:rollback and deleting the file + the row in the migration table. but the question is if it's an official way?
If you haven't shared the migrations with anyone and the code isn't in production, just rollback the migrations and edit the original one with your new definition
Create a new migration to change the existing column. you'll need to composer require doctrine/dbal for this to work... unless that table has an enum field in it, in which case you'll need to write ALTER statements manually.
This is why you have the up and down function in your migrations. So you can roll them back and add them in later as well
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('active')->default(0);
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('active');
}
}
When you run php artisan migrate the column will be added. When you run php artisan migrate:rollback it will remove the column for you. This way you can always rollback!