How to build a FastAPI app with MySQL database (step by step guide)

  Рет қаралды 32,561

Eric Roby

Eric Roby

Күн бұрын

In this video, we will guide you through the process of creating a FastAPI blog application integrated with a MySQL database, using SQLAlchemy for database interaction. You'll learn to define data models with Pydantic and how to use MySQL Workbench for database management. Finally, we'll show you how to serve your application using uvicorn.
🎥 React + FastAPI: • How to build a React +...
🎥 AWS Lambda + FastAPI: • Deploy FastAPI on AWS ...
🎥 MongoDB + FastAPI: • Unlocking the Power of...
🎥 PostgreSQL + FastAPI: • How to build a FastAPI...
🎓 Courses can be found:
FastAPI Beginner & Advanced: www.udemy.com/course/fastapi-...
Learn Chatbot Development: www.udemy.com/course/the-comp...
Want to learn how to use MySQL Workbench, a unified visual tool for database architects, developers, and DBAs? I will guide you on how to visually design, model, generate, and manage databases.
Throughout the video, we'll be sharing lots of tips and tricks that we've learned over the years. You'll be well-equipped to handle a wide variety of FastAPI projects by the end of this tutorial.
🔔 Subscribe to our channel to keep up with our latest content, and hit that like button if you find this tutorial helpful!
===========================
🔥 Check out the FastAPI Masterclass : www.udemy.com/user/ericroby2/
===========================
🛒 GEAR & RECOMMENDED BOOKS: kit.co/codingwithroby
TIMESTAMPS:
00:00 - Introduction
01:05 - FastAPI, SQLAlchemy, uvicorn, pydantic installation
02:27 - FastAPI Database File
04:37 - Create SQLAlchemy & MySQL Database Models
09:23 - FastAPI
14:00 - MySQL Workbench
15:46 - FastAPI endpoints
#codingwithroby #fastapi #mysql

Пікірлер: 84
@ushared-a-chregion3720
@ushared-a-chregion3720 Күн бұрын
really hot stuff Eric, thx for this very good explanation!
@demolazer
@demolazer 11 ай бұрын
Thank you so much for this. Great explanation and structure for a beginner. I now have a clear framework to build on top of.
@codingwithroby
@codingwithroby 11 ай бұрын
Woot woot! Glad you were able to learn and find value 🙂
@williamvinct
@williamvinct 11 ай бұрын
Hi Eric thank you so much for the clear explanation, your code is really clean
@codingwithroby
@codingwithroby 11 ай бұрын
Thank you so much 🙂 Glad you were able to find a lot of value!
@bhartendupandya3824
@bhartendupandya3824 17 күн бұрын
Amazing, loved it! best content.!
@codingwithroby
@codingwithroby 17 күн бұрын
Thank you so much 😀 Woot woot!
@ronjones1587
@ronjones1587 7 ай бұрын
Thank you ! You are the best!
@codingwithroby
@codingwithroby 6 ай бұрын
No - YOU'RE the best 🙂
@diassagatov9784
@diassagatov9784 6 ай бұрын
amazing video, learned a lot! Tnx!
@codingwithroby
@codingwithroby 6 ай бұрын
Awesome sauce!
@ItsEclipse.X
@ItsEclipse.X 9 күн бұрын
this guy is so underrated
@ItsEclipse.X
@ItsEclipse.X 9 күн бұрын
amazing editing
@codingwithroby
@codingwithroby 9 күн бұрын
Thank you so much 😊
@kavindulakmalw
@kavindulakmalw 8 ай бұрын
Thank you so much for the this tutorial. keep it up.
@codingwithroby
@codingwithroby 8 ай бұрын
You're welcome!
@shreyashverma1773
@shreyashverma1773 6 күн бұрын
Amazing !!
@codingwithroby
@codingwithroby 6 күн бұрын
You're amazing!
@izapawlukowska4545
@izapawlukowska4545 5 ай бұрын
thanks king
@roozensn
@roozensn Ай бұрын
Thanks a lot! Very helpful for beginners like me
@codingwithroby
@codingwithroby Ай бұрын
Glad it was helpful!
@alamos2404
@alamos2404 9 ай бұрын
Excelente explicacion!😄
@codingwithroby
@codingwithroby 9 ай бұрын
Yay! Glad you like it 🙂
@volodyslove
@volodyslove 9 ай бұрын
Nice explanation 😁 Thanks
@codingwithroby
@codingwithroby 9 ай бұрын
I am glad you enjoyed it 🙂
@InspireBeforeExpire-my6fm
@InspireBeforeExpire-my6fm 3 ай бұрын
working correct
@witty.coder1
@witty.coder1 4 ай бұрын
Thats so great sir. I am learning form you
@codingwithroby
@codingwithroby 4 ай бұрын
Glad to hear that!!
@svcomplex1
@svcomplex1 9 ай бұрын
Thanks! Cool video. Greetings from Russia!
@codingwithroby
@codingwithroby 9 ай бұрын
Glad you liked it!
@dianavaleriaovallevaldes1980
@dianavaleriaovallevaldes1980 3 ай бұрын
many thankssss!!😿
@codingwithroby
@codingwithroby 3 ай бұрын
You bet!
@richter9911
@richter9911 6 ай бұрын
for update we use db.put at the end?
@Kay-ip9fy
@Kay-ip9fy 4 ай бұрын
Thanks!
@codingwithroby
@codingwithroby 4 ай бұрын
No problem!
@nillsonsilva5896
@nillsonsilva5896 3 ай бұрын
It works very well, however, how do i do an update for my posts ?
@kal.
@kal. 5 ай бұрын
where is the video on how to setup the mysql workbench? couldnt find it
@manojk1494
@manojk1494 11 ай бұрын
2:07 I used to install dependencies one by one or by reading from a text file but this is new info thanks bro.
@codingwithroby
@codingwithroby 11 ай бұрын
Nice! Glad you were able to learn something new 🙂 Using a requirements.txt file is probably the best solution to installing multiple dependencies at once if you already have that defined… but if you are installing multiple dependencies to a brand new project keep it all on the same line and pip install them together!
@manojk1494
@manojk1494 11 ай бұрын
Thanks for your response!
@codingwithroby
@codingwithroby 11 ай бұрын
Of course! If you ever have any questions or need anything just post them here 🙂
@archanan1340
@archanan1340 4 ай бұрын
Hii i have one doubt we can connect already existing database and tables also
@warisshaikh9474
@warisshaikh9474 3 ай бұрын
Super cool and easy steps salut to u sir love from karachi pakistan ❤
@codingwithroby
@codingwithroby 3 ай бұрын
Thanks!
@florenciapesoa9015
@florenciapesoa9015 11 ай бұрын
I really liked the video. Can I use the same steps but with MariaDB?
@codingwithroby
@codingwithroby 11 ай бұрын
It should work very similar!
@ushared-a-chregion3720
@ushared-a-chregion3720 Күн бұрын
I have one question to it. How can I join tables ?
@elan311X
@elan311X 10 ай бұрын
Thank you so much for this, it's highly insightful _ please can you drop the syntax for update either post or user by user id as well as get all users.
@codingwithroby
@codingwithroby 10 ай бұрын
Hey friend! If you check out some of my other FastAPI videos I go over a whole bunch of different database queries and how they work 🙂
@ericflynn5799
@ericflynn5799 10 ай бұрын
Great video, I have a small question. Whenever I delete a post and then add a new one, the post id will start from where it was last ended. For example if I create post 2 then delete it and then add another post, the new post will start from id 3. Is there anyway to reset the post id to fill in from the smallest id not being used?
@codingwithroby
@codingwithroby 10 ай бұрын
While it might seem like a good idea to "recycle" IDs to fill gaps, there are several reasons you might not want to do this, especially if you're new to development: The biggest reason is data integrity. If you've deleted a post and reuse its ID, you might end up with links, references, or logs that point to the wrong content. This is bad for data accuracy. Think of how Foreign Keys work. If you have another piece of data that references that post, and then you delete the post, the old piece of data now references the new data point. Overall, majority of the time you do not want to reuse primary keys once they have been created, and that is why by default databases do not reuse.
@ericflynn5799
@ericflynn5799 10 ай бұрын
@@codingwithroby makes sense! Thank you for the clear explanation.
@k.a.93
@k.a.93 5 ай бұрын
cool
@mehul4mak
@mehul4mak 8 ай бұрын
Why you do not provide Id when creating user still it gets id number automatically?
@user-jv6nh5to4i
@user-jv6nh5to4i Жыл бұрын
Next, could you cover the authentication and the authorization in FastAPI?
@codingwithroby
@codingwithroby Жыл бұрын
Not a bad idea! I will look into adding this into a future video
@aestriex
@aestriex 3 ай бұрын
How do we implement HTML/CSS front-end into this application? Also, can a user login/registration system be implemented? (where users can sign up for an account and then make posts, for example)
@jake115577
@jake115577 29 күн бұрын
kzfaq.info/get/bejne/ZuCSZc6gzb--eYE.htmlsi=aj3W_RmtQuIOScD3
@azer0013
@azer0013 2 ай бұрын
You did use Sql for chating with the data?
@codingwithroby
@codingwithroby 2 ай бұрын
Yes, this video is using SQL.
@danielnahuncalcinafuentes3772
@danielnahuncalcinafuentes3772 Жыл бұрын
Hello, and how would be the query to get all the post of my table, without selecting one?
@codingwithroby
@codingwithroby Жыл бұрын
Great question! Try doing: return db.query(Post).all()
@usmonbekravshanov6933
@usmonbekravshanov6933 10 ай бұрын
Could you show your code in terms of asynchronous programming? Because here you declaring api views as asynchronous functions which do not await for db calls
@codingwithroby
@codingwithroby 10 ай бұрын
You probably do not need to use the async here. I added it just so people could see what a final state may look like
@abdullahmusheer4238
@abdullahmusheer4238 3 ай бұрын
as a newbie, i have a question, how can i host it so that external users can use it? i know we should secure it (whitelisting ip/tokens etc) but how can i load this python app to the internet for access to external users. thanks
@Manojkumar-fq2vu
@Manojkumar-fq2vu Ай бұрын
use vercel, or render bro
@iftikhar58
@iftikhar58 6 ай бұрын
but in this code , sql connnection established again and again for each request that bad things
@codingwithroby
@codingwithroby 6 ай бұрын
Nope that is a good thing - You do not want to keep connection on API requests!
@lapislazuli1949
@lapislazuli1949 2 ай бұрын
where is PUT request?
@youdontknowme4241
@youdontknowme4241 14 күн бұрын
It is showing that could not import module “main”. I have done everything as per video. Idk whats wrong?
@alifmahmud2946
@alifmahmud2946 14 күн бұрын
i have the same problem here.....bro..please let me know if you find any solution
@codingwithroby
@codingwithroby 11 күн бұрын
Make sure within your terminal you are in the correct folder where the main.py file lives.
@mr_don_key
@mr_don_key 23 күн бұрын
you didn't make a foreign key in the model ;-) (user_id is just a integer column, instead of a foreign key for id in user table)
@codingwithroby
@codingwithroby 23 күн бұрын
Yeah, I did this because then the comments would shift to "wtf is a fk" lol. So, I remove those outliers.
@Gamingman12362
@Gamingman12362 6 ай бұрын
damn i cant even create a virtual enviroment, that's how unprepared I am.
@codingwithroby
@codingwithroby 6 ай бұрын
Ha this made me laugh - you got this!
@eriguzy
@eriguzy 8 ай бұрын
i got this erroe AttributeError: module 'sqlalchemy.orm.session' has no attribute '__module__' how do i fix it please?
@codingwithroby
@codingwithroby 8 ай бұрын
This is hard without me seeing any code 😢 Perhaps it is something small and you can compare your code to the video again
@eriguzy
@eriguzy 8 ай бұрын
@@codingwithroby please sir i would like to send the pictures of the errors to you via your social media, this is my exam project and i am behind time,let me know which platform i can send the screenshot asap i really need help
@eriguzy
@eriguzy 8 ай бұрын
hey i fixed it>>>it was a lowercase mistake of sessionlocal instaed of Sessionlocal while i was importing, thanks for the video...i will be glad if theres any video on user registration and login with authentication as well for this blog app
FastAPI Just Got a HUGE Update!
6:19
Eric Roby
Рет қаралды 19 М.
How to build a FastAPI app with PostgreSQL
27:37
Eric Roby
Рет қаралды 39 М.
THEY WANTED TO TAKE ALL HIS GOODIES 🍫🥤🍟😂
00:17
OKUNJATA
Рет қаралды 22 МЛН
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 16 МЛН
Why You NEED To Learn FastAPI | Hands On Project
21:15
Travis Media
Рет қаралды 153 М.
How I’d learn ML in 2024 (if I could start over)
7:05
Boris Meinardus
Рет қаралды 983 М.
Build an SQL Agent with Llama 3 | Langchain | Ollama
20:28
TheAILearner
Рет қаралды 4 М.
"I Hate Agile!" | Allen Holub On Why He Thinks Agile And Scrum Are Broken
8:33
Python FastAPI Tutorial: Build a REST API in 15 Minutes
15:16
Unlocking the Power of NoSQL: FastAPI with MongoDB
23:57
Eric Roby
Рет қаралды 32 М.
Writing My Own Database From Scratch
42:00
Tony Saro
Рет қаралды 175 М.
THEY WANTED TO TAKE ALL HIS GOODIES 🍫🥤🍟😂
00:17
OKUNJATA
Рет қаралды 22 МЛН