Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vivification's avatar

Add new column to migration - but change order

Hello

So if i create a migration with columns id, number, date, status....

Run migration, my table is created..

But now I want to add a new column called "terms"

I create new migration,

>> php artisan make:migration add_terms_to_f_quotes_table --table=f_quotes

Then I add my new column name, following documentation.

public function up()
    {
        Schema::table('f_quotes', function (Blueprint $table) {
            $table->string('terms');
        });
    }

However this has put the column name at the end of the tables.

Is there a way to change the order in which it appears in the table.... e.g. before an existing column?

0 likes
5 replies
forrestedw's avatar

Like this:

public function up()
    {
        Schema::table('f_quotes', function (Blueprint $table) {
            $table->string('terms')->after('column_name');
        });
    }
forrestedw's avatar

@cronix it is useful to order columns so that when to check them in something like Sequel Pro they are in a convenient place.

Also, I like to keep things logical at all levels of my code. So for example I always put my relational cols (eg model_id) together in alphabetical order.

stefanbauer's avatar

Additional hint: I wouldn't care about the order in the database much when you already have an application which is running on production. It doesn't make any difference if the field is before or after another field. The only downside you get, if you have millions and millions of records, reordering/adding columns before/after will take a huge amount of time instead of just adding at the end.

Please or to participate in this conversation.