phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Forcibly re-run a migration

Open anwar-gazi opened this issue 10 years ago • 7 comments

I executed a migration which gone wrong, so next time I fixed the code inside that migration and then tried the php -f migration command but this time that migration didn't run

anwar-gazi avatar Dec 15 '15 09:12 anwar-gazi

@minhaj-resgef there is not currently a force command, although I have plans for one.

proposed syntax:

phinx migrate --force 2923092109

robmorgan avatar Dec 15 '15 09:12 robmorgan

hi dev, thanks, is there any way to manually clear that cache?

Sent from my phone. On Dec 15, 2015 3:57 PM, "Rob Morgan" [email protected] wrote:

@minhaj-resgef https://github.com/minhaj-resgef there is not currently a force command, although I have plans for one.

— Reply to this email directly or view it on GitHub https://github.com/robmorgan/phinx/issues/717#issuecomment-164707429.

anwar-gazi avatar Dec 15 '15 10:12 anwar-gazi

@minhaj-resgef yes, open your database. Find the phinxlog table and deleted the specified row that represents your migration.,

robmorgan avatar Dec 15 '15 10:12 robmorgan

I've written a php script to do that automatically. And further, added a -f switch to delete migration history and run again. I want to share the code.

anwar-gazi avatar Apr 09 '16 10:04 anwar-gazi

The best way I have to try out migrations while developing is this:

  1. run migration, but only part of it works
  2. comment out what reverts in down() what has not run
  3. migrate rollback
  4. fix up(), uncomment pieces of down()
  5. migrate
  6. did not work? repeat.

You basically revert the half-migration using its own down() until you get it right. This way you do not have to deal with half-changes in the database or phinxlog table by hand.

igorsantos07 avatar May 18 '16 20:05 igorsantos07

I dont think given the many side effects that a better solution can be found here. The given workaround is the best approach.

dereuromark avatar Nov 03 '25 16:11 dereuromark

@dereuromark thanks Mark for resolving this after 10 years ;)

robmorgan avatar Nov 04 '25 00:11 robmorgan