Laravel Migrations: 12 Useful Tips in 12 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 107

  • @mabdullahsari
    @mabdullahsari 3 ปีที่แล้ว +84

    00:10 - Foreign Keys in Laravel 7 and below
    01:35 - constrained() and nullable()
    02:15 - Delete Parent: Restrict or Cascade?
    04:10 - Change Order of Migrations
    05:05 - What Migrations Have (not) Run?
    05:40 - Timestamps with Default Value
    06:23 - Customize Default Migration File
    07:28 - Export Migrations into One SQL File
    08:38 - Drop Multiple Columns
    09:05 - Rollback or Refresh X Steps
    09:57 - Auto-increment starting value
    10:45 - Make Migration: Spaces vs Underscores

  • @adebajooluwaseyi2124
    @adebajooluwaseyi2124 3 ปีที่แล้ว +20

    You keep producing videos that are worthy of Oscar Award every time.
    Man! You are the real deal

  • @christopherokonkwo
    @christopherokonkwo 3 ปีที่แล้ว +3

    Very clean and clear. What I love most about your videos is that that theirs no ambiguity at all. You're the best.👍

  • @peterson.associates
    @peterson.associates 3 ปีที่แล้ว +2

    Thank you so much for contributing to the Laravel community! It's high quality content, well spoken, and I quite enjoy the topic as well. Farewell!

  • @redamakarem3737
    @redamakarem3737 3 ปีที่แล้ว

    You are a gem in the Laravel community
    Respect

  • @MaximilianoBernasconi
    @MaximilianoBernasconi 2 ปีที่แล้ว +1

    😍 i realy love your tips , and hope to be able to pay some day for those courses , tyvm for all the hard work

  • @ivan_adamovich
    @ivan_adamovich 3 ปีที่แล้ว

    You are the best teacher of Laravel, Thank you!

  • @mariopproenca
    @mariopproenca 3 ปีที่แล้ว +1

    Thank you for sharing these tips! Your channel videos are simply amazing, simple, extremely useful, and inspiring.

  • @YousefAltafWasti
    @YousefAltafWasti 10 หลายเดือนก่อน +1

    Thanks, I have learned new tricks I didn't know about.

  • @ИгорьД-к9ч
    @ИгорьД-к9ч 3 ปีที่แล้ว +2

    Another thing that may be helpfull - add unique number for migration class and name:
    php artisan make:migration users_fix_`date +%N`
    this will add nanoseconds value to migration name and class name making it abolutly unique.
    Work in unix systems only.

  • @mitchierichie
    @mitchierichie 3 ปีที่แล้ว

    Your videos are always worth watching. Thank you.

  • @breakinant
    @breakinant 3 ปีที่แล้ว +1

    Your videos are so helpful and I'm learning so much from them, thanks a lot!

  • @cobratst
    @cobratst 3 ปีที่แล้ว +1

    great content
    also for migration names you can use:
    php artisan make:migration AddFieldsToUsersTable
    and it will add underscores

  •  3 ปีที่แล้ว +1

    01:35 I learnt it the hard way. Edit: Thanks, I learned a lot!

  • @peterf983
    @peterf983 ปีที่แล้ว +1

    Short tip and I know soft delete exist. Thanks!

  • @gfonsecap
    @gfonsecap 2 ปีที่แล้ว +1

    You can also use camelCase on migrations and it will add _ and lowercase letter on each capital... I think that's even faster

  • @CODINGISEASY
    @CODINGISEASY 3 ปีที่แล้ว +1

    *Nice tips I learned a few things, thanks!*

  • @AARP41298
    @AARP41298 2 ปีที่แล้ว +1

    im happy that i use the same rename method to change the order of migration and i dont have evern 1 year of laravel experience

  • @abrahamnzau254
    @abrahamnzau254 3 ปีที่แล้ว

    Very Informative 👏👏

  • @Somcoders
    @Somcoders 3 ปีที่แล้ว +1

    Another usefull video , Thank You!

  • @coder236
    @coder236 3 ปีที่แล้ว

    Incredible tutorials, thankyou so much.

  • @shasimshahzad
    @shasimshahzad 3 ปีที่แล้ว

    Very useful, as always. Thank you very much!

  • @learncodeinbangla9181
    @learncodeinbangla9181 3 ปีที่แล้ว

    Awesome teaching

  • @marcelodheni
    @marcelodheni 3 ปีที่แล้ว +1

    Great content, tyvm.

  • @simon_leen
    @simon_leen 3 ปีที่แล้ว

    Great content as always

  • @coolcha
    @coolcha 3 ปีที่แล้ว +1

    Thank you for this video. I know you have covered this elsewhere, but I can't recall - how do you add foreign keys to existing columns. For e.g. I have a table which is like user_id but I did not mention it was a foreign key at first. Is there a way to retroactively add that in?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +3

      You can create a new migration file and add $table->foreign('user_id')->references('id')->on('users');
      But you need to make sure that current data does not violate that constrain, that there's no record with non-existing user_id.

    • @coolcha
      @coolcha 3 ปีที่แล้ว

      @@LaravelDaily So nullable cannot be applied in this way?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      @@coolcha It can be applied, but if you already have values that don't have corresponding parent values, then nullable won't help.

    • @coolcha
      @coolcha 3 ปีที่แล้ว

      @@LaravelDaily I see. Thank you for all your guidance and help.

  • @Hoobeal
    @Hoobeal 3 ปีที่แล้ว

    Hello, what is the extension to be able to visualize in the code if it is a table or a column? thanks for your tutorials!

  • @loukiidris7033
    @loukiidris7033 3 ปีที่แล้ว

    thank you so much your tutoreil it's very helpful

  • @vladyslavbondarenko4983
    @vladyslavbondarenko4983 3 ปีที่แล้ว

    Thanks! Very useful tips!

  • @Jameskaguo
    @Jameskaguo 3 ปีที่แล้ว +1

    you are the best

  • @imamhsn195
    @imamhsn195 3 ปีที่แล้ว

    Thanks you Sir for the awsome tips. I have a question on staps. In migrations sometimes we create for adding or removing colums or other, so at that time we dont need softDeletes is there any option to avoid softDeletes of other custom fields when we creating migration for columns?

  • @bumblebity2902
    @bumblebity2902 3 ปีที่แล้ว +4

    Sir, your forgotten one of most typical Junior developer mistakes, they do any migration mutations in existing migration files, although they must do in seperate files.

  • @КонстантинС-ж1ы
    @КонстантинС-ж1ы 3 ปีที่แล้ว

    I would additionaly tell about "--table" and "--create" parameters in php "artisan make:migration". And maybe "php artisan make:model SomeModel -m"

  • @nclsv
    @nclsv 3 ปีที่แล้ว

    More of these tips 👍

  • @ziyad_adel
    @ziyad_adel 3 ปีที่แล้ว

    Love you so much sir ❤️❤️

  • @naimsolong
    @naimsolong 3 ปีที่แล้ว

    Great sharing, thanks!

  • @IvanFirestone
    @IvanFirestone 3 ปีที่แล้ว

    Which IDE are you using? And what’ extension?

  • @abelenocrodriguez
    @abelenocrodriguez 3 ปีที่แล้ว

    Awesome, Very Useful!

  • @AbdelrahmanEl.Monshed
    @AbdelrahmanEl.Monshed 2 ปีที่แล้ว

    really appropriate thanks

  • @hamzashan8349
    @hamzashan8349 3 ปีที่แล้ว

    Can u make video on localization for both vuejs and blades files for multi language vue application which is also running with blades features .

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      This is how we use it: th-cam.com/video/pYtzXPrigKE/w-d-xo.html

  • @muhammadmuneeb4122
    @muhammadmuneeb4122 3 ปีที่แล้ว

    If i want to change the column type, like string to datetimes from my database table, what is the best solution for this?

  •  3 ปีที่แล้ว

    Great content, 1 question, should I use key type based on the project size, like integer for small and big integer for larger project... or use biginteger everywhere like default. Is it worth trading some performance for faster coding

  • @ArunKumar-kb1bb
    @ArunKumar-kb1bb 3 ปีที่แล้ว

    Very helpful. Thanks

  • @maysonhori
    @maysonhori 3 ปีที่แล้ว

    Man, i love you! serious

  • @dbelyaev
    @dbelyaev 3 ปีที่แล้ว

    Dear Povilas!
    Do you have Laravel lessons series about scaling?
    For example, if you're doing complex social network (like TH-cam clone), how to scale it infinitely?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      Hi, scaling is a very very individual thing, depending on the project and actual problems to solve: is it a DB issue? is it a Laravel code optimization issue? is it just adding more servers? etc. So it's very hard to create any kind of "definite" lessons on this topic. Maybe in the future I will come up with something.

  • @uchchhash-dev
    @uchchhash-dev 3 หลายเดือนก่อน

    Great video

  • @salimedia33
    @salimedia33 3 ปีที่แล้ว

    Very helpful 👍😍

  • @tarikmanoar
    @tarikmanoar 3 ปีที่แล้ว

    Thanks a lot It help me lot

  • @atikpatwary4584
    @atikpatwary4584 3 ปีที่แล้ว

    dear sir, will you create a tutorial about Alibaba E-commerce website API integration ?

  • @dhanushkafernando6316
    @dhanushkafernando6316 3 ปีที่แล้ว

    Thank you povilas

  • @codewithtee
    @codewithtee 3 ปีที่แล้ว

    Thanks for another one 😊

  • @ThibautLefebvre
    @ThibautLefebvre 3 ปีที่แล้ว

    I love your channel :)

  • @algeriennesaffaires7017
    @algeriennesaffaires7017 3 ปีที่แล้ว

    Can you do a video updating Laravel 7 to 8

  • @shokhzodnematov3840
    @shokhzodnematov3840 3 ปีที่แล้ว +2

    fine

  • @rambo_wagon
    @rambo_wagon 3 ปีที่แล้ว

    This is excellent

  • @cecilaw5504
    @cecilaw5504 3 ปีที่แล้ว

    When to use constrained() on a foreign key?🤔

  • @xuandungho
    @xuandungho 3 ปีที่แล้ว

    Thanks you !

  • @nicolas.chauvet
    @nicolas.chauvet 3 ปีที่แล้ว +5

    10:25 "Six million dollar man" mode

  • @diatm1506
    @diatm1506 3 ปีที่แล้ว

    Thank Sir

  • @abdqz5370
    @abdqz5370 3 ปีที่แล้ว

    sry to bother you my master teacher i have a question
    when i write the following command
    $table->foreignid('table_name')->constrained('table_name');
    should i put it right after the foreign key table or in the primary key migration file
    if the first, how can i tell the laravel which primary key from which table to constrain ?
    laravel 8 version
    thanks in advanced .....

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      Not sure I understand your question, please read the official documentation laravel.com/docs/8.x/migrations#foreign-key-constraints

  • @mannusaraswat3864
    @mannusaraswat3864 3 ปีที่แล้ว

    Great tips ...

  • @burnt3436
    @burnt3436 3 ปีที่แล้ว

    Is there a way to do a cascading soft delete?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      Yes. Here's my article: blog.quickadminpanel.com/one-to-many-with-soft-deletes-deleting-parent-restrict-or-cascade/

  • @boredom509
    @boredom509 2 ปีที่แล้ว

    Can you help me, when i do the 'php artisan migrate' it doesn't migrate any file from database/migrations. And when i check at my database there are only Migrations table created in it. I tried the migrate:rollback but it show 'nothing to rollback', i tried the php artisan migrate again and again but it just showing 'nothing to migrate'

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      Maybe you have put migrations innwrong folder? Or maybe you've called the classes/methods in nonstandard way so Laravel doesnt recognize them?

    • @boredom509
      @boredom509 2 ปีที่แล้ว

      @@LaravelDaily I dont think so because i just created this new project and follow a tutorial from the beginning, and their migration works but mine dont.

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      Sorry, I can't debug it for you.

    • @boredom509
      @boredom509 2 ปีที่แล้ว

      @@LaravelDailyIt's okay, Thanks for replying🙏🏾

  • @GergelyCsermely
    @GergelyCsermely 3 ปีที่แล้ว

    Thanks

  • @chandraauliatama6384
    @chandraauliatama6384 2 ปีที่แล้ว

    can we export migration and seeder into one sql file?

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      Yes, but not from Laravel, from your database client Export function.

  • @Stoney_Eagle
    @Stoney_Eagle 3 ปีที่แล้ว

    Foreign constraints give me headaches 🤯
    I collect data from the movie db api and EVERY key value can be missing...
    I had every record linked to a parent... Took me ages to get right.
    I had to remove ALL the constraints for seasons because many TV shows fails the queue job.
    At least I still have the TV constraint to remove everything belonging to that 😖

  • @sombiri9147
    @sombiri9147 3 ปีที่แล้ว

    wow, great!!!

  • @web2works
    @web2works 3 ปีที่แล้ว

    Surpise there's no mention of $table->foreignIdFor($model)

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      It's not really widely used, even Taylor mentioned once on Twitter that he's not a fan of it, because model may change and then it breaks.

  • @chirengito
    @chirengito 3 ปีที่แล้ว

    nice job new abonnée

  • @paweu1660
    @paweu1660 3 ปีที่แล้ว

    Please turn on the subtitles

  • @yetimtade5816
    @yetimtade5816 3 ปีที่แล้ว

    Can u make video laravel-websockets

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว +1

      I don't work with websockets currently, so can't make a video about it.

  • @alila3883
    @alila3883 3 ปีที่แล้ว

    fantastic

  • @cardboarddignity
    @cardboarddignity 2 ปีที่แล้ว

    I am not fan of saving few milliseconds while not typing the underscore, but I'm a fan of not breaking my fingers, since for some reason I find it kinda difficult to type underscore with one hand :/

  • @santhoshkumar-sf4bc
    @santhoshkumar-sf4bc 3 ปีที่แล้ว

    will we lost data by rollback sir??

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      Yes if you delete the table/columns on rollback

    • @santhoshkumar-sf4bc
      @santhoshkumar-sf4bc 3 ปีที่แล้ว

      @@LaravelDaily how to update migration files... like Add columns or modify datatypes without loss table data sir??

  • @Shez-dc3fn
    @Shez-dc3fn 3 ปีที่แล้ว

    i hate timestamps.. because? there is a limit i found out that in mysql at least timestamp() will stop working from year 2038 or something... so maybe your system/app wont be around but w/e..

  • @firdavs.ibodullayev
    @firdavs.ibodullayev 3 ปีที่แล้ว

    Great

  • @ЭдуардСухарев-ш9ч
    @ЭдуардСухарев-ш9ч 3 ปีที่แล้ว

    How come that I get to know new things even though I'm from Symfony camp? O_o

  • @eas7112
    @eas7112 3 ปีที่แล้ว

    can you make a video with use withMax() on pivot table price column?

    • @LaravelDaily
      @LaravelDaily  3 ปีที่แล้ว

      Good suggestion, will do.

    • @eas7112
      @eas7112 3 ปีที่แล้ว

      @@LaravelDaily ok thankyou, all i know withMax() is can't used on pivot table, i tired use
      user_id | project_id | rating
      User::withMax('projects', 'project_user.rating')
      it seems work, but the sql look weird ;(
      and also tired create a new model method user hasMany project relate to the pivot table,
      user_id | project_id | rating
      just don't know any better way to do this

  • @cuttysauce
    @cuttysauce 2 ปีที่แล้ว

    Great video. Thanks!

  • @MJacksi
    @MJacksi 3 ปีที่แล้ว

    Thank you!

  • @mohamednabih6036
    @mohamednabih6036 3 ปีที่แล้ว

    Thanks

  • @sajjadboodaghi9638
    @sajjadboodaghi9638 2 ปีที่แล้ว

    Great

  • @noushedakib1658
    @noushedakib1658 2 หลายเดือนก่อน

    Great