What to put in down() function if up() drops table?

266 views Asked by At

Just starting to learn Laravel, so go easy. I made a couple migration files to try out. The first creates a table, the second adds a column, and the third drops the table. I'm curious to know what I should put in the down() function of the third migration, since you can't "undrop" a table. How do you handle rolling back a migration that drops a table?

1

There are 1 answers

0
Kryten On

The point of the down function is to restore the database to the same state it was in before you ran the up function. So if up() drops a table, then down() should recreate that table.

It is important to note that you probably will lose data if you do this. But migrations are intended to manage the scheme of the database, not the contents. If you want to preserve the data, that's a backup.