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?
question from:
https://stackoverflow.com/questions/65929552/fastapi-column-products-category-id-does-not-exist 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…