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.
▶️ 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
This whole fucking tutorial has helped me bring an application to life, but this one in particular really saved my hide. Thanks!
Appreciate it!
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.......
Thank you very much. For a long time I could not understand why it did not work until I came across your comment.
life saver
How did you find this? Thanks a lot!!
@@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,
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!
Migration was giving me a migraine...this helped massively!!!
Happy to hear it!
After A long Time 🔥 Flask 😎😎
Yes!
Only I think that this guy needs millions of likes and subscribers?
agreed
Thanks a lot, this video just save my job.
Happy to help!
Very informative video...John👍
Glad you enjoyed it!
You need to run `flask db upgrade` right after `flask db migrate -m '...'` for this to work properly. Thanks for great tutorial!
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
fantastic tutorial! Thank you!
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 ??
Sorry, I don't use or recommend pycharm ever. If you don't want those errors, use the tools I use ;-)
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"
@@everardoguevara5765 glad you got it sorted out
@@everardoguevara5765 Thanks !!
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.
Outstanding, thank you.
Welcome!
This is hilarious, I can't believe this worked.
:-)
8:50 is where the business at
Ha
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
Great Sir!!
Thanks!
Thank you! I so lik Flask Friday!
welcome!
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?
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.
Thank you so much
Very Welcome!
amazing, thank's
Thank you too!
In memory database? Adding flask migrate to existing project is a different process as shown in extention author's Miguel video.
this is pretty common best practices
@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
Hard to say... is your virtual environment turned on?
thanks you!
Welcome!
Heard of Svelte? I guess you would be a great person to learn Svelte from :)
Although I am intermediate in svelte lol
What's that?
Thanks for portuguese subtitles
Are there?
thanks, mine is saying command flask not found when i run flask db init. help please
What did you do differently from the video? Did you turn your virtual environment on?
migration command is not working. i used workbench to create the field password_hash.any problem?
If you use different tools than me, I can't really help you. Obviously it's a problem if it's not working...
@@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.
goodr
thanks
@codemy.com do you have a tut on how to insert data into tables with one to one relationship... kind regards
Yes I believe so
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