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...
The Flask community is indebted to you, Anthony Hubert. Thank you for all your helpful videos.
Thank you very much Anthony. You explain concepts very well and the project example you deliver is easy to hand on.
Extremely helpful, the blank DB trick fixed my problems
Thank you 🍀
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
Nice video. Very useful. Thanks
Thanks for watching!
great one again! thanks for this
Thanks for watching!
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 ❤
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
Thanks, how to open PostgreSQL in browser ?
Is there any way to run init db and migrate db in the code itself instead of cli
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
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)
why docker file
?