Curso de FastAPI - Rest API com Python - Aula 03: Banco de Dados, Modelos e Migrações

Want to learn more about our Complete Python Course? Click the link below to secure your spot in the next class: https://lp.hashtagtreinamentos.com/es... CLICK AND ACCESS THE FREE AUTOMATION MINICOURSE AT PYTHON: https://dlp.hashtagtreinamentos.com/p... ----------------------------------------------------------------------- 📁 Files Used in Video: https://dlp.hashtagtreinamentos.com/p... 💻 Recommended video: FastAPI Course Playlist - Rest API with Python (Complete Backend)    • Curso de FastAPI - Rest API com Python (Ba...   ----------------------------------------------------------------------- Case Prefer the video in text format: https://www.hashtagtreinamentos.com/c... ----------------------------------------------------------------------- TO HIRE HASHTAG FOR YOUR COMPANY: https://www.hashtagtreinamentos.com/t... ----------------------------------------------------------------------- Let's move on to the third lesson of the FastAPI Course - REST API with Python (Complete Backend)! In this lesson, you will learn how to create, structure, and version databases professionally using SQLAlchemy and Alembic. You'll see how to transform Python models into database tables with SQLAlchemy's ORM, define fields with validations, create relationships with PrimaryKey and ForeignKey, and apply best practices to keep your backend flexible and scalable. We'll build the User, Order, and OrderItem tables together, control values with ChoiceType, and understand the role of the _init_ method to instantiate objects safely and efficiently. I'll also show you how to use the Alembic library to manage database versions, create and apply migrations with the revision and upgrade commands, and resolve common errors during the migration process. 📌 Enjoying this comprehensive content on APIs with Python? Then subscribe to the channel, activate the bell, and leave a like to follow all the lessons in our complete FastAPI course! ----------------------------------------------------------------------- Hashtag Programming ► Subscribe to our channel: http://bit.ly/3c0LJQi ► Turn on notifications (click the bell)! ► Like our video! ----------------------------------------------------------------------- Social Media ► Blog: https://bit.ly/2MRUZs0 ► YouTube: http://bit.ly/3c0LJQi ► Instagram: https://bit.ly/3o6dw42 ► Facebook: http://bit.ly/3qGtaF2 Here in the videos on the Hashtag Programming channel, we teach several Python tips so you can develop in this programming language and create your own projects and automations! ----------------------------------------------------------------------- Class Content 00:00 Introduction to Databases in FastAPI 00:58 Overview of Databases in FastAPI 01:28 What is SQLAlchemy and how the ORM works 02:45 Creating a database with SQLAlchemy in FastAPI 06:55 How to model tables with Python classes 14:00 Rules and validations in the database 15:00 How to define a primary key in SQLAlchemy 16:27 Adding default values to fields 17:47 Understanding the _init_ function in models 22:41 Creating the Order table with a relationship 25:30 Setting up a foreign key in the database 35:06 Creating an order item table (relationship) 41:54 What is database migration in FastAPI 43:00 How to configure Alembic in the FastAPI project 49:43 Generating a database Data and Migration with Alembic 50:55 Understanding the migration process step by step 52:15 Fixing errors with Alembic and SQLAlchemy Utils 54:00 Viewing SQLite databases in VS Code 54:25 How to fix migration errors in Alembic 57:00 Creating new migrations after changes 59:12 Conclusion #python #hashtagprogramming