Move a table column with a Laravel migration
How to reposition a column in a Laravel migration with after(), first() and change(), which databases support it, the risks involved, and when to leave column order alone.
Moving a column in Laravel usually means changing where an existing column sits in a table's physical definition. For example, you might want phone to appear right after email instead of at the end of the users table. Laravel can do this on some databases and not others. Even where it works, the change is often cosmetic. This review explains what a column move changes, where it is supported, what can break, and when a different approach is the better choice.
Short verdict: is moving a column worth it?
On MySQL or MariaDB, repositioning a column through a migration works and is easy to write. The benefit is a table definition that reads in a logical order in database clients, schema dumps and SELECT * output. The cost is that the database may rebuild the table. Also, the migration has to restate the column's full definition, and a missed attribute is easy to lose. On PostgreSQL, SQLite and SQL Server, Laravel's position modifiers do not reorder existing columns, so the move is not a practical option there.
Leaving the physical order alone is usually better in these cases: the table is large and busy, the order only matters for how data is displayed or exported, or the project runs on a database without positional support. In those cases, control the order where it is presented, such as in queries, API resources or export mappings, rather than in storage.
What "move a column" can mean
The phrase is used for several different tasks, and they need different migrations:
- Reposition within the same table: change the column's ordinal position without touching its data. This is the main subject here.
- Place a new column at a specific position: add a column with after() or first() instead of letting it land at the end.
- Rename a column: change its name, not its position. Laravel's renameColumn handles this.
- Move a column to another table: create the new column, copy the data, update code, then drop the old column. This is a data migration, not a reorder.
What a column move actually changes
A reorder changes only the column's position in the table definition. The column's name, type and stored values stay the same, and so does how Eloquent reads and writes it by name. The new order shows up wherever the database lists columns in definition order. That includes SELECT * results, DESCRIBE output, database GUI tools, schema dumps and some export utilities.
Stored order and presented order are not the same thing. An explicit select list, an API resource or a CSV export definition decides its own column order no matter how the table is defined. If your goal is a specific order in a report or download, change the presentation layer. The schema does not need to change.
How to reposition a column on MySQL or MariaDB
Laravel documents after() and first() as MySQL-specific column modifiers. When adding a column, attach after() to place it after a named column, or first() to make it the first column. To move an existing column, combine the modifier with change(). The example below is illustrative: it assumes a users table where phone was previously placed after remember_token.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone', 32)->nullable()->after('email')->change();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone', 32)->nullable()->after('remember_token')->change();
});
}
};
Since Laravel 11, change() modifies columns natively, and Laravel's upgrade guidance says the column definition must include every attribute you want to keep. Examples are length, nullable, default, unsigned, charset and comment. Anything left out is dropped. Before writing the migration, check the current definition with your database client or SHOW CREATE TABLE, and copy each attribute into the change() call.
Older Laravel releases that depended on doctrine/dbal for change() did not reliably apply position modifiers. If you are on an older version, or the generated SQL does not include the position clause, a raw statement is the dependable fallback:
use Illuminate\Support\Facades\DB;
DB::statement('ALTER TABLE users MODIFY phone VARCHAR(32) NULL AFTER email');
A raw statement ties the migration to MySQL syntax, and the full column definition still has to be restated. Write the down() method so it moves the column back to its original neighbour. That way, a rollback restores the previous layout.
To add several new columns together at one position, Blueprint also has an after() method that accepts a column name and a closure. Columns defined inside the closure are placed in sequence after the named column.
Database support at a glance
| Database | Reorder an existing column | Notes |
| MySQL | Yes | after() and first() with change(), or ALTER TABLE ... MODIFY ... AFTER |
| MariaDB | Yes | Same syntax as MySQL |
| PostgreSQL | No | No ALTER syntax for column position; reordering means recreating the table |
| SQLite | No | Position modifiers are not applied |
| SQL Server | No | No ALTER syntax for column position; tools that appear to reorder recreate the table |
Recreating a table just to change its column order means copying data and rebuilding indexes, constraints, foreign keys and permissions. That is rarely justified for appearance alone. Where it is required, treat it as a planned data migration, not a quick schema tweak.
Risks to check before running it
- Table rebuild: MySQL's online DDL documentation lists column reordering as an operation that rebuilds the table. Duration depends on table size and server load, so test on a production-sized copy before deploying.
- Lost attributes: a change() call that omits a default, nullability or comment silently removes it.
- Positional code: anything that relies on column position rather than name will see different data. This includes INSERT statements without a column list, numeric-index fetches and scripts that read SELECT * by position.
- Environment drift: if a teammate's local database is SQLite and production is MySQL, the move applies in one place and not the other. Schema dumps from the two environments will then differ.
Will the new order hold up in exports and shared data?
A reorder is only visible to consumers that follow definition order. A CSV produced from SELECT *, a mysqldump file, or a spreadsheet import that maps columns by position will reflect the new layout. Downstream users who expect the old order may then misread or mis-import the data. Exports with explicit column lists or header-based mapping are not affected.
If other people or systems receive files from this table, check whether they map columns by header name or by position before you move anything. When they rely on position, an export with an explicitly defined column order is safer than depending on the table layout.
Evidence gaps
No measurements were available for this review. That means no timings for table rebuilds, no lock durations and no version-by-version test results. The behaviour described comes from documented Laravel and database features and general SQL principles. Confirm the generated SQL on your exact Laravel version, for example with php artisan migrate --pretend. Test on a staging copy of the real table before running the migration in production.