Back

How to update database table when change the Migration ?


If I change the Migration Structure (such like CreatePasswordResetsTable)

How I to change the database table ?

php artisan migrate:refresh will Delete my original data....

ftiersch replied 1 year ago Solution

You don't change migrations. Every time you need to change the database you create a new migration, that's the point about them.

So for example:

  • You create your initial tables and run php artisan migrate
  • The next day you notice you forgot the field "status" in one of the tables. So you create a NEW migration called "add_status_to_table" (for example, the name is not important of course :)) and you add the field in the up() method and remove it in the down() method (that's important if you want to be able to roll back the migration). Now you run php artisan migrate again.
  • Two weeks later you notice that you need a new table (or field) for a functionality. Again you run php artisan make:migration to create a NEW migration, change the database and run php artisan migrate.
gclove replied 1 year ago

Cool~ Thank you !

JCarlosR replied 8 months ago

There is no way to delete rows in the migrations table?

luis02lopez replied 6 months ago

Hello @ftiersch What do you refer when you said: creat with up() method and remove with down() method? Are you talking about the:

php artisan up php artisan down ?

Thanks

abejordan replied 3 months ago

@luis02lopez The up() method is called when you do the php artisan migrate command, and the down() method is called when you do the php artisan migrate:rollback command. Check out the docs: https://laravel.com/docs/5.4/migrations


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us