Re: [sqlalchemy] sqlalchemy returns None for sqlite tables which already have data
like someone mentioned there, showing the classes doesn't say much.I'd check that the table name is correct and definitely matches what's in the SQLite database that you are actually accessing, as well as that the primary key column in those tables is actually a primary key, or at least not NULL values. On Mon, May 22, 2023, at 8:53 AM, m7mđ ĕğý wrote: > Hello mates, > > As my last msg had a so bad format i will keep the link of my original > question on stackoverflow : > > https://stackoverflow.com/questions/76304295/sqlalchemy-returns-none-for-sqlite-tables-which-already-have-data > > > i hope i get answers from you mates. > > Thanks > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/530d0f09-8624-4f38-9a29-711a79a1d6d1n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/530d0f09-8624-4f38-9a29-711a79a1d6d1n%40googlegroups.com?utm_medium=email_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/92475a97-d14e-4751-8f03-afa3f1b6f485%40app.fastmail.com.
[sqlalchemy] sqlalchemy returns None for sqlite tables which already have data
Hello mates, As my last msg had a so bad format i will keep the link of my original question on stackoverflow : https://stackoverflow.com/questions/76304295/sqlalchemy-returns-none-for-sqlite-tables-which-already-have-data i hope i get answers from you mates. Thanks -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/530d0f09-8624-4f38-9a29-711a79a1d6d1n%40googlegroups.com.
[sqlalchemy] sqlalchemy returns None for sqlite tables which already have data
there is something wrong with those two sqlite tables: select method returns none but the table already have data. is that because product class is Primary key and a foreign key at the same time? - i use sqlalchemy - those two tables returns none every time i try to query them. - ihave other tables in the sqlite database which working as expected. only those two table behave like so for sorry i dont know why is that happening. or how to fix it class Product(Base): __tablename__ = 'products' id = Column(Integer, primary_key=True , nullable=False) name = Column(String, nullable=False) price = Column(Float, nullable=False) category = Column(String, nullable= False) description = Column(String, nullable=False) brand = Column( String(200)) is_available = Column(Boolean, nullable=False) stock_count = Column(Integer) ship_range = Column(DateTime) created_at = Column(DateTime) updated_at = Column(DateTime) slug = Column(String, unique=True, nullable= False) orders = relationship('Order', back_populates='product') carts = relationship('Cart', back_populates='product') product_owner = Column(String, ForeignKey('doctors.id')) ProductOwner = relationship('UserDoctor', back_populates='products') def __repr__(self) -> str : return f"({', '.join( f'{k}={v!r}' for k, v in self.__dict__.items() if k != '_sa_instance_state')})" class Cart(Base): __tablename__="carts" id = Column(Integer, primary_key=True, nullable=False) user_id = Column(Integer, ForeignKey('users.id')) user = relationship('User', back_populates='carts') product_id = Column(Integer, ForeignKey('products.id')) product = relationship('Product', back_populates='carts') def __repr__(self): return f"{self.__class__.__name__}({', '.join(f'{k}={v!r}' for k, v in self.__dict__.items() if k != '_sa_instance_state')})" i try the form session.query(User).all() to query data and other forms also but it always returns None although there are data in the table. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/95601db3-fcbf-4861-8594-6e3b0fd9b6a1n%40googlegroups.com.