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

osherdo's avatar

Can't drop column with dropColumn()

Hey I want to remove the column age from the table users. When running php artisan migrate it returns:

nothing to migrate

Here's my migration. How do I remove this column?

public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('username',20); 
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
            $table->dropColumn('age');

        });
    }
0 likes
7 replies
tykus's avatar

Which database server are you using?

tykus's avatar

So wait, is this the original migration with the dropColumn now added?

The idea of migrations is that you can have database schema changes persisted in a VCS. So you have an original create_users_table migration and you're happy with that for a while; but then you want change the users table; so you make a new migration to do just that; you do not change the original (unless you are going to reset everything).

Create a new migration from the commandline:

php artisan make:migration drop_age_column_from_users

Now you have a new migration file to make the necessary changes to the schema:

class DropAgeColumnFromUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
    Schema::table('users', function (Blueprint $table)
    {
        $table->dropColumn('age');
    });
    }

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
    Schema::table('users', function (Blueprint $table)
    {
        $table->integer('age')->unsigned(); // puts the age column back in the table whenever you rollback this migration
    });
}
}
osherdo's avatar

Yes - I have added dropColumn in order to remove the column 'age'. It's mentioned in the docs:

To drop a column, use the dropColumn method on the Schema builder:

Schema::table('users', function ($table) {
    $table->dropColumn('votes');
});

Should I create a migration just for dropping the 'age' column - that's what I understand from you.

Basically how can I remove it - if not from the migration? just do it with a sql query/ phpmyadmin directly? although I prefer do it with a migration.

tykus's avatar
tykus
Best Answer
Level 104

Should I create a migration just for dropping the 'age' column - that's what I understand from you.

Correct

1 like
spekkionu's avatar

Every change to your database should be a new migration. Migrations are only run once so changing a migration that has already run will result in nothing happening.

Think of migrations like version control for your database where each migration tells how to get to the next "version".

2 likes

Please or to participate in this conversation.