In case someone got the error saying "No details". Its because u need to restart the server again. So its better that u add the keyword --reload after the uvicorn command. Then try again it will run smoothly
Great content! Can you please explain why some tutorials use pydantic models(schemas) AND sql models (models)? I find this confusing and causing issues.
That's how it worked in the paste but then the developer of fastapi created sqlmodel which use pydantic and sqlalchemy under the hood to make our life much easier ,i think most people in youtube are not aware that sqlmodel exist
I am new to fastapi and all backend stuff. Maybe I ask silly question but kindly response me ASAP as I am learning it on my full power 😅 How can I deploy it on vercel? As I've been deploying it on vercel previously without any database. The file db.sqlite how can I manage that. For example me app is in production and wanted to do some changes in APIs or add new tables. And give it a push to github for auto deploy on vercel. Won't it wipe the previous database? How can I protect the latest database. I am much confused on this.
Why should one create subclasses and inherit from a base class? Is there a reason you shouldn't just, for example, put the primary key field in the parent class?
Endpoint functions are defined as `async def`, but the db operations inside are all sync, including the get_session depency. This is bad in a real project. async def endpoints are running in an event loop, time cosuming db operations are not awaited, so they will block the event loop.
I thought too, but it actually raises an error at Runtime when trying to fetch object: sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[Shop(shop)], expression "relationship('list[Product]')" seems to be using a generic class as the argument to relationship(); please state the generic argument using an annotation, e.g. "products: Mapped[list['Product']] = relationship()"
Timestamp: 18:30. Even after adding `None` to the `band_id` at runtime I'm getting "pydantic_core: 1 validation error for AlbumBase" "band_id missing". I am using Progres instead of SQLite.
I also had a problem around this video time. The error returned was not so clear. To solve the problem in my case, I had to transform the "album.release_date" from string to datetime.date. It was something more or less like this: if band_data.albums: for album in band_data.albums: raw_album_date = album.release_date.split("-") year = int(raw_album_date[0]) month = int(raw_album_date[1]) day = int(raw_album_date[2])
@@Ceddybaer I added "default=None" to the parameters of Field() on line 23, ie band_id: int | None = Field(default=None, foreign_key="band.id") But the error still remains
This is incredibly well produced and deeply informative. Thank you.
Thanks a lot, delighted to hear that! Cheers!
Bro thank you for creating these videos, deeply respect!
Thanks a lot for the comments bro, cheers!
Lots of value in this video, thanks!!
Thanks a lot!
Can you show hoz to set up FastAPI with MySQL and PostGreSQL (especially with the async features)?
also setting up with postgres docker and traefik .Also an additional content can be sending emails and show how to create email templates
In case someone got the error saying "No details". Its because u need to restart the server again. So its better that u add the keyword --reload after the uvicorn command. Then try again it will run smoothly
Great tip for development!
Great content! Can you please explain why some tutorials use pydantic models(schemas) AND sql models (models)? I find this confusing and causing issues.
Maybe single responsibility principle
That's how it worked in the paste but then the developer of fastapi created sqlmodel which use pydantic and sqlalchemy under the hood to make our life much easier ,i think most people in youtube are not aware that sqlmodel exist
Why did you not chose SQL Alchemy for this demonstration ?
I am new to fastapi and all backend stuff. Maybe I ask silly question but kindly response me ASAP as I am learning it on my full power 😅
How can I deploy it on vercel? As I've been deploying it on vercel previously without any database. The file db.sqlite how can I manage that. For example me app is in production and wanted to do some changes in APIs or add new tables. And give it a push to github for auto deploy on vercel. Won't it wipe the previous database? How can I protect the latest database. I am much confused on this.
Why should one create subclasses and inherit from a base class? Is there a reason you shouldn't just, for example, put the primary key field in the parent class?
Endpoint functions are defined as `async def`, but the db operations inside are all sync, including the get_session depency. This is bad in a real project. async def endpoints are running in an event loop, time cosuming db operations are not awaited, so they will block the event loop.
can you give an example of changing a DB operation to support async?
Please do more on the crud operations as well as error handlings please
A video on env config and file structure for bigger projects would also be helpful
Is SQLModel still necessary with SQLAlchemy 2.0?
Love from Nepal❤
Thanks a lot!
Hey, do you consider making an unpoly video? I feel like the library is so underrated.
It has been on the list for a while, yeah. I'll try and get that done soon.
can we also get one for microservices using gRPC
great one.
Thanks as always!
great video
Thanks a lot!
Best content!
Thanks a lot!
Instead of converting the type to a string, you can do `from __future__ import annotations`
I thought too, but it actually raises an error at Runtime when trying to fetch object: sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[Shop(shop)], expression "relationship('list[Product]')" seems to be using a generic class as the argument to relationship(); please state the generic argument using an annotation, e.g. "products: Mapped[list['Product']] = relationship()"
Weird 🤔
Timestamp: 18:30. Even after adding `None` to the `band_id` at runtime I'm getting "pydantic_core: 1 validation error for AlbumBase" "band_id missing". I am using Progres instead of SQLite.
I also had a problem around this video time. The error returned was not so clear. To solve the problem in my case, I had to transform the "album.release_date" from string to datetime.date.
It was something more or less like this:
if band_data.albums:
for album in band_data.albums:
raw_album_date = album.release_date.split("-")
year = int(raw_album_date[0])
month = int(raw_album_date[1])
day = int(raw_album_date[2])
album_date = date(year, month, day)
album_obj = Album(
title=album.title,
release_date=album_date,
band=band
)
session.add(album_obj)
I ran into the same issue on SQLite. I fixed it by adding "default=None" to the parameters of Field().
@@Ceddybaer I added "default=None" to the parameters of Field() on line 23, ie
band_id: int | None = Field(default=None, foreign_key="band.id")
But the error still remains
@@Ceddybaer Nice! I like this solution, thank you 😃.
dyed your hair?
raise ValueError(f"{type_} has no matching SQLAlchemy type")
ValueError: has no matching SQLAlchemy type
restAPI,sqlmodel,alembic. docker .compose and metrics
Alembic + FastAPI + SQLModel early this week! Thanks.