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

Mrs_Beginner's avatar

Add new column to existing table

hi, i want to add new column to existing table. i created new empty table and named this to "meta12meta" for some reasons. but i wanted to add some column to it without loosing old data. "meta12meta" table migration is like below code:

class CreateAnotherTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            //
        });
    }
}

and i did another migration with below command:

php artisan make:migration add_column_to_metatable --table="meta12meta"

and this new migration have below code :

class AddColumnToMetatable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('metakey');
            $table->string('metavalue');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('meta12meta', function (Blueprint $table) {
            $table->dropColumn('id');
            $table->dropColumn('metakey');
            $table->dropColumn('metavalue');
        });
    }
}

when i run ~~~ php artisan migrate ~~~ some errors will happen.

i used this solution to add new column (https://stackoverflow.com/questions/16791613/add-a-new-column-to-existing-table-in-a-migration) but i got below error:

[Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.meta12meta' doesn't exist (SQL: alter table `meta12meta` add `id` int unsigned not null auto_increm
  ent primary key, add `metakey` varchar(255) not null, add `metavalue` varchar(255) not null)



  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.meta12meta' doesn't exist



  [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mapi.meta12meta' doesn't exist

and i checked laravel docs but no idea how to solve this problem. my laravel version is 5.5 and ~~~ composer require doctrine/dbal ~~~ is installed.

do you have any idea?

0 likes
2 replies
Yorki's avatar
Yorki
Best Answer
Level 11

Table mapi.meta12meta doesn't exist in your database. Check its existance first. To create new table you have to use Schema::create method instead of Schema::table which is used to modifying existing tables.

1 like
Mrs_Beginner's avatar

@Yorki thank you so much, after i read your answer again i found my stupidity. thank you

Please or to participate in this conversation.