Povilas, thanks for a detailed explanation. A little notation: migrate:rollback with step option rollbacks a specific count of last migrated migrations, not more than one batch. For rollback a specific batch you need to use the batch option and pass the batch value from the migrations table.
Laravel Daily is seriously the best resource. I spend every day browsing the docs for on-demand needs, but Laravel Daily really keeps me learning and growing as a developer. Thank you so much for your amazing channel.
Before migrating, first time I use '--pretend' flag to see what actually will change. It`s like double check for me to see, what have I written in laravel and what will actually be done in database.
@@gotoslovakia I don't think so, but you coul create an alias command such as php artisan migrate:pretend to see whats going on before you actually migrate
Thanks Povilas for your great tips as always. 👏 👏 👏 One additional tip is that `php migrate --step` gives each migration a unique batch id which you allows you the ability to rollback each migration individually. This is especially handy during development.
i like the explanation. personally, I use php artisan migrate:refresh --path=migration_file.php and I totally agree with the down methods, there are lots of data lost if not careful.
I usually have a down() method while I'm developing, so I can do easy rollbacks, but then I'll comment out the down() method before deploying to production.
I use rollback all the time on my local environment, for example even writing migration and testing it. And it's not a good idea to fresh all tables every time because I have some data already and I'm authorised for example... But I never use rollback on production of course.
isn't down method is good for example: you ship a new feature with new DB columns that are "not null", But when deploying you found out the code had an issue that impactfull on users so you decide to revert the changes from git and deploy again, but now the column still exists and its throws new error becouse previouse code doesn't handle it ... I think the down method is good only for immediate rollback after deploying for large-scale applications, in case something is not right so you have controll on the state of you application. other than that, yeah, no need for it.
What if you already have data on a table and you have to do some updates like adding a column or two, is it possible to do that with migrate command or you can only do it manually ?
excuse me sir, what happen if some project laravel is not use model, i mean the flow is from controller get data and then throw to view? thank you before, i hope you'll answer my question
with greetings! I have a question, Sometime when developer run migrate:refresh (or accidentally delete database by giving this command), data gone, Can we add some kind of double check using artisan command (like: are you sure to run this command, this will remove all data! Y/N?) before executing this command???
Hi I accidentally "php migrate --refresh" my database and unfortunately all tables dropped when I wanted to connect again I'm facing some issues. Actually the website is in Linux Server where the front end is vue , backend is laravel & the database in mysql. I have an issue in login page where it produces error "the server responded with a status of 500 (Internal Server Error):8080/api/login". The laravel.log produced this error [2023-01-12 15:24:19] local.ERROR: Argument 2 passed to Symfony\Component\HttpFoundation\Response::__construct() must be of the type int, null given, called in opt/lampp/htdocs/dnephp/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 55 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 2 passed to Symfony\\Component\\HttpFoundation\\Response::__construct() must be of the type int, null given, called in /opt/lampp/htdocs/dnephp/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 55 at /opt/lampp/htdocs/dnephp/vendor/symfony/http-foundation/Response.php:199). Is there anywhere to solve this?
Povilas, thanks for a detailed explanation. A little notation: migrate:rollback with step option rollbacks a specific count of last migrated migrations, not more than one batch. For rollback a specific batch you need to use the batch option and pass the batch value from the migrations table.
The only explanation I found that actually explains it!! Thank you!
Laravel Daily is seriously the best resource. I spend every day browsing the docs for on-demand needs, but Laravel Daily really keeps me learning and growing as a developer. Thank you so much for your amazing channel.
Before migrating, first time I use '--pretend' flag to see what actually will change. It`s like double check for me to see, what have I written in laravel and what will actually be done in database.
Is there any possibility to enable --pretend by default?
Is there any possibility to enable --pretend by default?
@@gotoslovakia I don't think so, but you coul create an alias command such as php artisan migrate:pretend to see whats going on before you actually migrate
Thanks Povilas for your great tips as always. 👏 👏 👏
One additional tip is that `php migrate --step` gives each migration a unique batch id which you allows you the ability to rollback each migration individually. This is especially handy during development.
i like the explanation. personally, I use php artisan migrate:refresh --path=migration_file.php
and I totally agree with the down methods, there are lots of data lost if not careful.
Been using Laravel 5+ years. Never used down migrations.
I usually have a down() method while I'm developing, so I can do easy rollbacks, but then I'll comment out the down() method before deploying to production.
Thanks for the clarity
I did mess up! One-month data was lost because of that.
Hi have a problem ,
I refresh the migration but now i can't login again because auth::attempt return always false.
I use rollback all the time on my local environment, for example even writing migration and testing it. And it's not a good idea to fresh all tables every time because I have some data already and I'm authorised for example...
But I never use rollback on production of course.
Hi Povilas, doesn't migrate:rollback --step, limit the roll back migration files you suggest instead of rolling back batches?
isn't down method is good for example:
you ship a new feature with new DB columns that are "not null", But when deploying you found out the code had an issue that impactfull on users so you decide to revert the changes from git and deploy again, but now the column still exists and its throws new error becouse previouse code doesn't handle it ...
I think the down method is good only for immediate rollback after deploying for large-scale applications, in case something is not right so you have controll on the state of you application.
other than that, yeah, no need for it.
What if you already have data on a table and you have to do some updates like adding a column or two, is it possible to do that with migrate command or you can only do it manually ?
It is possible and it is how you should do it
@@krekas how is it done ?
@@ailtondevesse4738 read docs about migration
@@ailtondevesse4738 E.g. "php artisan make:migration add_username_to_users" gets you started
@@yezperdk and then "php artisan migrate" to run the new migration (to get you ended)
excuse me sir, what happen if some project laravel is not use model, i mean the flow is from controller get data and then throw to view? thank you before, i hope you'll answer my question
What do you mean by "what happen"?
@@LaravelDaily the data flow, still same or not?
Yes, same.
How to get data back? I accidentally run "php artisan migrate:fresh"
There's no way, unfortunately.
with greetings! I have a question, Sometime when developer run migrate:refresh (or accidentally delete database by giving this command), data gone, Can we add some kind of double check using artisan command (like: are you sure to run this command, this will remove all data! Y/N?) before executing this command???
I think Laravel will ask you to confirm automatically, if APP_ENV=production, from what I remember
@@LaravelDaily yes, laravel ask about in prod, but I am asking for local/dev end, some kind of custom command.
lol that meme made my day ahahhaha
Hi I accidentally "php migrate --refresh" my database and unfortunately all tables dropped when I wanted to connect again I'm facing some issues. Actually the website is in Linux Server where the front end is vue , backend is laravel & the database in mysql. I have an issue in login page where it produces error "the server responded with a status of 500 (Internal Server Error):8080/api/login". The
laravel.log produced this error
[2023-01-12 15:24:19] local.ERROR: Argument 2 passed to Symfony\Component\HttpFoundation\Response::__construct() must be of the type int, null given, called in opt/lampp/htdocs/dnephp/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 55 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 2 passed to Symfony\\Component\\HttpFoundation\\Response::__construct() must be of the type int, null given, called in /opt/lampp/htdocs/dnephp/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php on line 55 at /opt/lampp/htdocs/dnephp/vendor/symfony/http-foundation/Response.php:199). Is there anywhere to solve this?