Avatar ·

How to add a new field to an existing table via migration in Laravel?

Hello, colleagues! I'm new to Laravel (version 10) and can't figure out migrations. Here's the situation: I already have a ready-made users table, which was created by the standard migration when installing Laravel. Now I need to add a new phone field (string type, optional) to it.

\n\n

I tried to simply edit the existing migration file create_users_table.php and add a new column there, but after running php artisan migrate nothing happens — it says "Nothing to migrate". I realized that this cannot be done because the migration has already been executed.

\n\n

Then I created a new migration via Artisan:

\n
php artisan make:migration add_phone_to_users_table
\n\n

I got a file 2024_01_15_1