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

Поделиться
HTML-код
  • Опубликовано: 30 ноя 2024

Комментарии • 34

  • @aramayis_mirzoyan
    @aramayis_mirzoyan Месяц назад +1

    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.

  • @luckss98
    @luckss98 Год назад +1

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

  • @ellmatic
    @ellmatic 2 года назад +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.

  • @TzK1991
    @TzK1991 2 года назад +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 2 года назад

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

    • @gotoslovakia
      @gotoslovakia 2 года назад

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

    • @patrick-dev
      @patrick-dev 2 года назад

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

  • @Samuel.Mwangi
    @Samuel.Mwangi 2 года назад +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.

  • @dkazinz
    @dkazinz 2 года назад +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.

  • @phoenixedge4049
    @phoenixedge4049 2 года назад +1

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

  • @yezperdk
    @yezperdk 2 года назад

    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.

  • @muhammadumair9771
    @muhammadumair9771 5 месяцев назад

    Thanks for the clarity

  • @SalomDunyoIT
    @SalomDunyoIT 2 года назад +1

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

  • @rezahakimi4015
    @rezahakimi4015 Год назад

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

  • @gotoslovakia
    @gotoslovakia 2 года назад

    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.

  • @miguelviegas9424
    @miguelviegas9424 2 года назад

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

  • @azzhraanee201128
    @azzhraanee201128 2 года назад

    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.

  • @ailtondevesse4738
    @ailtondevesse4738 2 года назад +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 2 года назад

      It is possible and it is how you should do it

    • @ailtondevesse4738
      @ailtondevesse4738 2 года назад

      @@krekas how is it done ?

    • @krekas
      @krekas 2 года назад

      @@ailtondevesse4738 read docs about migration

    • @yezperdk
      @yezperdk 2 года назад

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

    • @ellmatic
      @ellmatic 2 года назад +1

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

  • @dutanugraha3878
    @dutanugraha3878 2 года назад

    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

  • @CodingBirdsOnline
    @CodingBirdsOnline 2 года назад

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

  • @RehmanKhan-zv2rl
    @RehmanKhan-zv2rl 2 года назад

    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  2 года назад +1

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

    • @RehmanKhan-zv2rl
      @RehmanKhan-zv2rl 2 года назад

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

  • @sheldonknight7995
    @sheldonknight7995 2 года назад +1

    lol that meme made my day ahahhaha

  • @thaneshvaranravendran8390
    @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?