How To Migrate Database With Flask - Flask Fridays #11

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • In this video I'll show you how to change or update the columns in your database using Flask-Migrate to Migrate the Database!
    Anytime we make a change to our database by adding or removing columns from our database tables, we need to migrate those changes.
    In order to do that with Flask, we'll need to install and set up something called Flask-Migrate. In this video I'll show you how to change your database table in the code of your app itself, and then how to install and use Flask-Migrate.

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

  • @Codemycom
    @Codemycom  3 года назад +2

    ▶️ Watch Entire Flask Friday Playlist ✅ Subscribe To My RUclips Channel:
    bit.ly/3ig2eJn bit.ly/2IGzvOR
    ▶️ See More At: ✅ Join My Facebook Group:
    Codemy.com bit.ly/2GFmOBz
    ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
    Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
    ▶️ Get The Code
    bit.ly/2L1jBl5

  • @gofyourselfgoogle875
    @gofyourselfgoogle875 Год назад +5

    This whole fucking tutorial has helped me bring an application to life, but this one in particular really saved my hide. Thanks!

  • @sjackson330
    @sjackson330 Год назад +6

    Not sure if this will help anyone else, but I had to use the following commands in VS Code:
    - Instead of flask db init / I used flask --app=hello db init (there are two hyphens in front of app)
    - Instead of flask db / I used flask --app=hello db
    - and so on.....
    I'm not sure if I'm doing something wrong, but this worked for me.......

    • @user-fz6st2hs8n
      @user-fz6st2hs8n Год назад +1

      Thank you very much. For a long time I could not understand why it did not work until I came across your comment.

    • @DataQuestLive
      @DataQuestLive 8 месяцев назад

      life saver

    • @josebgeorge227
      @josebgeorge227 6 месяцев назад

      How did you find this? Thanks a lot!!

    • @Lucas.olv505
      @Lucas.olv505 5 месяцев назад

      ​@@josebgeorge227 IDK if was how he found this, but usually if you try to type exactly how was typed in the video you get in the vscode terminal the message in red: "Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory." And says right there: Use the 'flask --app' option,

  • @123pencilboy
    @123pencilboy 2 года назад +2

    I have to point out that flask db migrate will not work if the SQLalchemy model inherits "Base". Using flask-migrate with declarative base instead of db.model did not work for me. Once I got rid of declarative base it worked.
    Thanks for making this video!

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

    Migration was giving me a migraine...this helped massively!!!

  • @idk____idk6530
    @idk____idk6530 3 года назад +1

    After A long Time 🔥 Flask 😎😎

  • @user-ut5go5ni5d
    @user-ut5go5ni5d 10 месяцев назад

    Only I think that this guy needs millions of likes and subscribers?

  • @chatgptmaster-ym9ew
    @chatgptmaster-ym9ew 4 месяца назад

    Thanks a lot, this video just save my job.

  • @kunalpathak4875
    @kunalpathak4875 4 месяца назад

    Very informative video...John👍

    • @Codemycom
      @Codemycom  4 месяца назад

      Glad you enjoyed it!

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

    You need to run `flask db upgrade` right after `flask db migrate -m '...'` for this to work properly. Thanks for great tutorial!

    • @Codemycom
      @Codemycom  2 года назад +4

      I think I need to do exactly what I did in the video for it to work, as proven by it working in the video lol

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

    fantastic tutorial! Thank you!

  • @rickybobby7310
    @rickybobby7310 3 года назад +3

    Hi John, in pycharm I have this error when running flask dn init :
    Usage: flask db init [OPTIONS]
    Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
    Any clue ??

    • @Codemycom
      @Codemycom  3 года назад +1

      Sorry, I don't use or recommend pycharm ever. If you don't want those errors, use the tools I use ;-)

    • @everardoguevara5765
      @everardoguevara5765 3 года назад +5

      I had the same problem. I did not add the enviroment variables as in the first video. I added them and now I dont have problems. "export FLASK_ENV=development" and "export FLASK_APP=your_flask_main_file.py"

    • @Codemycom
      @Codemycom  3 года назад +1

      @@everardoguevara5765 glad you got it sorted out

    • @rickybobby7310
      @rickybobby7310 3 года назад

      @@everardoguevara5765 Thanks !!

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

    hi sir wheni try to migrate in flask or try to run flask run/flask db init or anything related to migration im getting value error : entry points must be listed in groups pls help me with this.

  • @teclote
    @teclote 10 месяцев назад

    Outstanding, thank you.

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

    This is hilarious, I can't believe this worked.

  • @almamanley
    @almamanley 3 года назад +2

    8:50 is where the business at

  • @oxrick1.080
    @oxrick1.080 7 месяцев назад

    Been following through your tutorials, appreciate a lot. I am using multiple (3) databases for my flask app but when im trying to run migrations for (2) database I get an error ERROR [flask_migrate] Error: Can't locate revision identified by 'e29e0dd49adf' which is used by migrate for my first db in its own directory, how do i solve this

  • @umeshpurohit5252
    @umeshpurohit5252 3 года назад

    Great Sir!!

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

    Thank you! I so lik Flask Friday!

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

    Using this replaces the need to create a schema.sql file and updating it as I'm adding to the db. Right?
    The SQLAlchemy and flask_migrate libraries are creating the schema for me in the background.
    Also, while not causing me an error, when I a import flask_migrate, I get this warning message: Import "flask_migrate" could not be resolved from sourcePylancereportMissingModuleSource)
    Not sure why. I followed the same steps as you. Is it because I am using different versions of everything?

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

      Correct.
      As for the error, are you using a different tool than me? I don't recommend visual studio code. Sounds like you haven't set the path to Python in your tool.

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

    Thank you so much

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

    amazing, thank's

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

    In memory database? Adding flask migrate to existing project is a different process as shown in extention author's Miguel video.

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

      this is pretty common best practices

  • @ayomikunadetayo645
    @ayomikunadetayo645 7 месяцев назад

    @Codemy
    I am new using flask, with your sessions, i am getting well along, but the Migration have been giving me migraine. I have been running into this error:
    Usage: flask [OPTIONS] COMMAND [ARGS]...
    Try 'flask --help' for help.
    Error: No such command 'db'.
    (VIRTUAL1) C:\Users\dell\Desktop\FLASK_B>
    Please i need your assistance on this

    • @Codemycom
      @Codemycom  7 месяцев назад

      Hard to say... is your virtual environment turned on?

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

    thanks you!

  • @plusk343
    @plusk343 3 года назад

    Heard of Svelte? I guess you would be a great person to learn Svelte from :)

    • @plusk343
      @plusk343 3 года назад

      Although I am intermediate in svelte lol

    • @Codemycom
      @Codemycom  3 года назад

      What's that?

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

    Thanks for portuguese subtitles

  • @al-aminibrahim1394
    @al-aminibrahim1394 2 года назад

    thanks, mine is saying command flask not found when i run flask db init. help please

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

      What did you do differently from the video? Did you turn your virtual environment on?

  • @mynameisgod1135
    @mynameisgod1135 3 года назад

    migration command is not working. i used workbench to create the field password_hash.any problem?

    • @Codemycom
      @Codemycom  3 года назад

      If you use different tools than me, I can't really help you. Obviously it's a problem if it's not working...

    • @mynameisgod1135
      @mynameisgod1135 3 года назад

      @@Codemycom your project is working well. I use vs code as editor. I failed in migration command. So I used workbench for creating new column .it was successful. No problem with flask. Everything okay.

  • @mugomuiruri2313
    @mugomuiruri2313 16 дней назад

    goodr

  • @pipi_delina
    @pipi_delina 3 года назад +1

    @codemy.com do you have a tut on how to insert data into tables with one to one relationship... kind regards

    • @Codemycom
      @Codemycom  3 года назад

      Yes I believe so

    • @pipi_delina
      @pipi_delina 3 года назад

      Can I share a repo of what am trying to achieve maybe u can show me a proper way to do it.. am kind of new to flask and sqlalchemy