Laravel Migrate: (Re)fresh, Rollback, or Reset?

Sdílet
Vložit
  • čas přidán 17. 08. 2022
  • There are quite a lot of commands for the migrations that look similar on the surface. Let me show you how they work, in practice.
    Related links:
    - Original Tweet by Jenniline Ebai: / 1553002440118611968
    - Do we still need Down migrations? Taylor says No. laraveldaily.com/still-need-m...
    - How to Structure Databases in Laravel: laraveldaily.teachable.com/p/...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses membership: laraveldaily.teachable.com/p/...
    - Laravel QuickAdminPanel: bit.ly/quickadminpanel
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: bit.ly/laravel-newsletter
    - My personal Twitter: / povilaskorop
  • Jak na to + styl

Komentáře • 33

  • @muhammadumair9771
    @muhammadumair9771 Před měsícem

    Thanks for the clarity

  • @TzK1991
    @TzK1991 Před rokem +12

    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
      @gotoslovakia Před rokem

      Is there any possibility to enable --pretend by default?

    • @gotoslovakia
      @gotoslovakia Před rokem

      Is there any possibility to enable --pretend by default?

    • @patrick-dev
      @patrick-dev Před rokem

      @@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

  • @ellmatic
    @ellmatic Před rokem +1

    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.

  • @luckss98
    @luckss98 Před 11 měsíci +1

    The only explanation I found that actually explains it!! Thank you!

  • @Samuel.Mwangi
    @Samuel.Mwangi Před rokem +4

    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.

  • @SalomDunyoIT
    @SalomDunyoIT Před rokem +1

    I did mess up! One-month data was lost because of that.

  • @dkazinz
    @dkazinz Před rokem +1

    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.

  • @rezahakimi4015
    @rezahakimi4015 Před rokem

    Hi have a problem ,
    I refresh the migration but now i can't login again because auth::attempt return always false.

  • @phoenixedge4049
    @phoenixedge4049 Před rokem +1

    Been using Laravel 5+ years. Never used down migrations.

  • @yezperdk
    @yezperdk Před rokem

    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.

  • @gotoslovakia
    @gotoslovakia Před rokem

    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.

  • @azzhraanee201128
    @azzhraanee201128 Před rokem

    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.

  • @CodingBirdsOnline
    @CodingBirdsOnline Před rokem

    How to get data back? I accidentally run "php artisan migrate:fresh"

  • @miguelviegas9424
    @miguelviegas9424 Před rokem

    Hi Povilas, doesn't migrate:rollback --step, limit the roll back migration files you suggest instead of rolling back batches?

  • @ailtondevesse4738
    @ailtondevesse4738 Před rokem +1

    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 ?

    • @krekas
      @krekas Před rokem

      It is possible and it is how you should do it

    • @ailtondevesse4738
      @ailtondevesse4738 Před rokem

      @@krekas how is it done ?

    • @krekas
      @krekas Před rokem

      @@ailtondevesse4738 read docs about migration

    • @yezperdk
      @yezperdk Před rokem

      @@ailtondevesse4738 E.g. "php artisan make:migration add_username_to_users" gets you started

    • @ellmatic
      @ellmatic Před rokem +1

      @@yezperdk and then "php artisan migrate" to run the new migration (to get you ended)

  • @dutanugraha3878
    @dutanugraha3878 Před rokem

    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

  • @RehmanKhan-zv2rl
    @RehmanKhan-zv2rl Před rokem

    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???

    • @LaravelDaily
      @LaravelDaily  Před rokem +1

      I think Laravel will ask you to confirm automatically, if APP_ENV=production, from what I remember

    • @RehmanKhan-zv2rl
      @RehmanKhan-zv2rl Před rokem

      @@LaravelDaily yes, laravel ask about in prod, but I am asking for local/dev end, some kind of custom command.

  • @sheldonknight7995
    @sheldonknight7995 Před rokem +1

    lol that meme made my day ahahhaha

  • @thaneshvaranravendran8390

    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?