I'm having a problem with sqlalchemy in Python.
I have the following files :
base.py:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
engine = create_engine('postgresql://postgres:mysecretpassword@localhost:5432/postgres',echo=True)
Base = declarative_base(engine)
Product.py:
from sqlalchemy import Table,Date,TEXT,Column,BIGINT,Integer,Boolean
from base import Base
class Product(Base):
__tablename__ = 'products'
id = Column('id',BIGINT, primary_key=True)
barcode = Column('barcode' ,BIGINT)
productName = Column('name', TEXT)
productType = Column('type', Integer)
maufactureName=Column('maufacture_name',TEXT,nullable=True)
manufactureCountry = Column('manufacture_country', TEXT)
manufacturerItemDescription = Column('manufacture_description',TEXT)
unitQuantity=Column('uniq_quantity',Integer)
quantity=Column('quantity',Integer)
quanityInPackage=Column('quantity_in_package',Integer)
isWeighted=Column('is_weighted',Integer)
picture=Column('picture_url',TEXT)
def __init__(self,args...):
.....
main.py:
from Product import Product
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from base import Base
Base.metadata.create_all()
Session = sessionmaker()
session=Session()
session.add(Product(...))
session.commit()
When I run the main I keep getting an error that the products relation doesn't exist :
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "products" does not exist
Any idea why ? From the sqlalchemy logs it doesn't seems like it even tries to create the table.