FastAPI column products.category_id does not exist

Viewed 604

I'm using FastAPI and I am stuck in this error while adding columns to a Model class

Here are my models

class Category(Base):
    __tablename__ = 'categories'

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, unique=True)
    description = Column(String)

    products = relationship("Product", back_populates="category")


class Product(Base):
    __tablename__ = 'products'
    
    id = Column(Integer, primary_key=True, index=True)
    category_id = Column(Integer, ForeignKey('categories.id'))
    title = Column(String, unique=True)
    price = Column(Float)
    cost = Column(Float)

    category = relationship("Category", back_populates="products")

when the API is running I got this error: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column products.category_id does not exist

And the problem go on, if I try to add a new attribute to Porduct model there are no changes in my database columns

There is something like run migrations in FastAPI? What I am missing?

1 Answers
Related