Create Sqlalchemy ORM class from regular class gets "has no attribute ''_sa_instance_state''"

20 views
Skip to first unread message

ScottBot

unread,
Mar 12, 2021, 6:10:34 AM3/12/21
to sqlalchemy
I have a game that I am coding for school (not a project or homework) and I am trying to use a SQLite database with sqlalchemy to store the game info. I don't know what the problem is or how I can fix it. Any help is appreciated. 
https://stackoverflow.com/questions/66591466/sqlalchemy-orm-from-regular-class

Simon King

unread,
Mar 15, 2021, 6:28:09 AM3/15/21
to sqlal...@googlegroups.com
I haven't followed your code in detail, but I think the problem might be here:

clazz = school.Class('12', 'A')

students = [
Student("Name1", "Sname1", clazz=clazz, code='aa7'),
Student("Name2", "Sname2", clazz=clazz, code='bb7'),
Student("Name3", "Sname3", clazz=clazz, code='cc7')
]

You are creating an instance of "school.Class", which is the
non-sqlalchemy base class. You probably meant to create an instance of
"Class", which is the SQLAlchemy-mapped subclass, didn't you?

Simon

On Fri, Mar 12, 2021 at 11:10 AM ScottBot <sfau...@gmail.com> wrote:
>
> I have a game that I am coding for school (not a project or homework) and I am trying to use a SQLite database with sqlalchemy to store the game info. I don't know what the problem is or how I can fix it. Any help is appreciated.
> https://stackoverflow.com/questions/66591466/sqlalchemy-orm-from-regular-class
>
> --
> 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+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/b3e6fb67-6cab-4484-8c39-a01999640e67n%40googlegroups.com.

Scott Faurholm

unread,
Mar 18, 2021, 10:33:41 AM3/18/21
to sqlal...@googlegroups.com
Yes, sorry I didn't follow up

You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/lpZVfrXIiy4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAFHwexcFYWK7yu9hW42LgUDB3LL%2BFAuCJqogpvYDjBe1MHigNQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages