I make changes in the migration files – specifically, I deleted one field and added a new one, I do a migration (php artisan migrate) but nothing works.
I make changes in the migration files – specifically, I deleted one field and added a new one, I do a migration (php artisan migrate) but nothing works.
2
Answers
If you have data and you don’t need to lose it, you can make a new migration file that deletes and add column let’s assume that we need to delete the
email_verified_at
column and add themobile_verified_at
column.php artisan make:migration drop_email_verified_at_and_add_mobile_verified_at_to_users_table
This will be the output of the previous command:
$table->dropColumn('email_verified_at');
$table->datetime('mobile_verified_at')->nullable();
The migration file code will be like this
You can either refresh whole table or what I do in these cases is go to the migrations table, find the migration name for the table you have done some changes and remove it from the migrations table. Then go to you code editor and try to migrate.
Other way – smarter one is, lets say you have posts table and you want to add image fields to that table:
Go to newly created migration and migrate it.
Also, in this case, if you want only to migrate newly created table you can migrate it like this:
Voila 🙂 Enjoy