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

santiago.correa.e's avatar

Add a new migration but without lossing data of the old tables

The thing is that I would need to add new tables in my database in the future, but when I create a new migration and run php artisan migrate, it shows an error because a table already exist, I know that rollback would work but it will delete all my data (I already have almost 3 millions records), I just can't let that happen, should I delete all the old migration? or what could I do?

How can I make a new migration without deleting the old one?

0 likes
3 replies
tim_jespers's avatar

@santiago.correa.e Can you share a code snippet of the migration that is causing the problem? My best guess at this point is that your up() function has a Schema::create('existing-table') instead of a Schema::table('existing-table'). If that is the case you simply defined the second migration as a "create table" migration instead of an "alter table" migration which can be resolved easily. for more info read the docs about columns

Cronix's avatar

Instead of creating a table in a migration, you can also alter an existing one.

When creating a table:

Schema::create('flights', function (Blueprint $table) {
  $table->string('some_field', 50);
});

When altering a table:

Schema::table('flights', function (Blueprint $table) {
  $table->string('some_field', 100)->change();
});

https://laravel.com/docs/5.4/migrations#modifying-columns

Please or to participate in this conversation.