How to Add Flask-Migrate to an Existing Flask-SQLAlchemy Project

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024
  • In this video I will go over how you can add Flask-Migrate to a project that already has an established database. Once you have Flask-Migrate set up properly, you'll be able to make any futures to your database through the Flask-Migrate workflow.
    Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
    Get the code I wrote in this video: prettyprinted....
    Twitter: / pretty_printed
    Github: github.com/pre...

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

  • @lator1941
    @lator1941 7 месяцев назад +4

    The Flask community is indebted to you, Anthony Hubert. Thank you for all your helpful videos.

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

    Thank you very much Anthony. You explain concepts very well and the project example you deliver is easy to hand on.

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

    Extremely helpful, the blank DB trick fixed my problems

  • @atillaalagoz4100
    @atillaalagoz4100 3 месяца назад

    Thank you 🍀

  • @tjkarthik2
    @tjkarthik2 Год назад +2

    You are pretty smart to skip the major real time problem... Scenario is, If there are some tables with relationships in your db already, when you run the migarate it will generate migration file for creating the tables and dropping, so you cant run either upgrade or downgrade on that time. because there will not be any cascading delete. so it will throw errors like, these tables have some dependencies

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

    Nice video. Very useful. Thanks

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

    great one again! thanks for this

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

    I am struggling, because i am on a windows machine and my terminal doesn't do the same thing as in the video
    i am using VSCode and my terminal looks like this
    "PS C:\...>"
    can anyone tell me what i need to do to get to the terminal with the "$"
    thanks ❤

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

    1. flask db migrate (this generates migration script for development DB)
    2. flask db upgrade (this runs the migration script)
    After connecting to production DB
    3. flask db stamp head (this literally stamps the head revision migration into the production DB - doesn't change schema)
    4. flask db upgrade (runs the migration script and upgrades the production DB to the head revision)
    I had issues with this. Here's what happened. I had existing migration files for my project, and after I ran `flask db migrate` and `flask db upgrade` for my development DB, it worked as expected. But on switching the DB to the production one, after `flask db stamp head` and `flask db upgrade` the production database did not reflect the new schema changes yet `flask upgrade` ran w/o errors.
    When I ran `flask db check`, it showed the new schema changes detected but they were unapplied. It was quite baffling.
    I was able to resolve this by
    1. stamping production db with last version before head e.g
    flask db stamp
    2. run flask db upgrade with revision id of head:
    flask db upgrade

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

    Thanks, how to open PostgreSQL in browser ?

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

    Is there any way to run init db and migrate db in the code itself instead of cli

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

    2:30 I have error: *KeyError: 'migrate'*
    Do you have any hint how to solve this problem? I've spent some time googling for solution but I failed

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

      You should have the below code in your project, then only flask knows that you have defined migration instance in your app.
      from flask_sqlalchemy import SQLAlchemy
      from flask_migrate import Migrate
      app = Flask(__name__)
      db = SQLAlchemy(app)
      migrate = Migrate(app, db)

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

    why docker file
    ?