I'm using migrations in cakephp to keep track of changes in my database. Let's say that I create a field in a table in the database and then I realize later on that I won't really need that field. How do I put the table to its previous state (the state when I did not add the column) using the migrations. I see that there are some functions up
and down
in the CakeMigration class but I have no idea how to use them.
Thank you
You don't put it to it's previous state, per se. You just create a new migration to delete the field.
Hopefully you're familiar with the basics of using the Migrations plugin. If so, you can just delete the column from your database using your chosen database management tool, then create a new migration:
And then choose the 'compare to database' option. Cake will pick up the fact that the column has been deleted, and will automatically generate the right code in the
up
anddown
arrays.Note, that means you'll have one migration to create the column, and then later, another to delete that same column. It feels a bit messy at first, but don't worry... it's the best way.