Search code examples
laravelcygwin

How to delete/refresh specific migration in laravel


I am working on a large project which has many migrations. I want to add a column in a table and I don't want to maintain multiple migrations for one table. How can I do that? Is there any way to migrate:refresh for only one migration?


Solution

  • I think migrations are designed to run sequentially as each one could depend on an earlier one.

    For example, migration#1 could create a table and migration#2 could add some extra fields to that table. If you tried to run migration#2 without every having run #1 then it would fail.

    When you run artisan migrate then it will only run migrations that haven't already been applied unless you use migrate:refresh in which case it will reset and re-run all migrations.

    If you are dead-set on only running one migration - you could temporarily remove all the migrations you do not want run from the directory, and run the migration command. Then move the rest back. It's a hacky workaround, but it would do the trick.

    There is ONE MORE alternative that I think might even suit you best:

    php artisan migrate --path=/database/migrations/selected/
    

    where the migration you want is inside the /selected/ directory (which you'll need to create).