I work on a webapp in Laravel 7. I created a migration to add some new columns to a table. Then I added code to work on those columns. All went fine.
However when I merged the new code to a new branch and tried to run the migrations to add the fields they require, I got an SQL error message telling me the some columns are missing.
It seems that running the php artisan migrate (or any other artisan commands) will execute the web.php file that already refers (indirectly) to the new columns that are not yet there causing this error message. Please see below the stack trace showing this:
[2022-02-27 16:28:08] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'LARAVEL_LOCALE' in 'field list' (SQL: select `ID`, `LARAVEL_LOCALE` from `LANGUAGE`) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'LARAVEL_LOCALE' in 'field list' (SQL: select `ID`, `LARAVEL_LOCALE` from `LANGUAGE`) at /Applications/MAMP/htdocs/gng2/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
...
#6 /Applications/MAMP/htdocs/gng2/app/GNG/GNGLangDAO.php(24): Illuminate\\Database\\Query\\Builder->get()
#7 /Applications/MAMP/htdocs/gng2/routes/web.php(26): App\\GNG\\GNGLangDAO->loadAllLocales()
#8 /Applications/MAMP/htdocs/gng2/vendor/laravel/framework/src/Illuminate/Routing/RouteFileRegistrar.php(35): require('/Applications/M...')
It sounds a bit strange to me that running php artisan migrate basically requires that migrations were already done. Is there any way to avoid executing the web.php file when running the migrations or can you recommend any other solution to the problem?
Thanks, W.
Finally I solved the problem by separating the migration and the code into two separate branches and committing them separately. This was lower risk for me than modifying the code for such a single time problem.