Thank you so much!

On Tuesday, April 19, 2016 at 9:58:40 AM UTC-4, Mike Bayer wrote:
>
>
> this issue involves the use of graphene-specific APIs which are not part 
> of the SQLAlchemy project.   You will have better luck asking the 
> maintainers of graphene directly. 
>
>
> On 04/19/2016 02:16 AM, 刘邦瑞 wrote: 
> > Hi, 
> > 
> > I encountered this problem when I try to use Automap methods in 
> Graphene. 
> > 
> > The situation is: I have an existing table 'cb_people' in MySQL 
> > databases under SCHEMA_NAME and want to auto map it to python class 
> > People like this: 
> > 
> > 
> > engine = create_engine('mysql+mysqldb://root:sync@localhost', 
> > convert_unicode=True) 
> > db_session = scoped_session(sessionmaker(autocommit=False, 
> > autoflush=False, bind=engine)) 
> > metadata = MetaData() 
> > metadata.reflect(bind = engine, schema = SCHEMA_NAME) 
> > Base = automap_base(metadata = metadata) 
> > Base.query = db_session.query_property() 
> > 
> > class People(Base): 
> >      __tablename__ = 'cb_people' 
> >      id = Column(Integer, primary_key=True) 
> >      object_id = Column(String(64), nullable=False) 
> >      first_name = Column(String(128), nullable=False) 
> >      last_name = Column(String(128), nullable=False) 
> >      birthplace = Column(String(128), nullable=True) 
> >      affiliation_name = Column(String(128), nullable=True) 
> > 
> > def init_db(): 
> >      Base.prepare(engine, reflect=True, classname_for_table = 
> 'cb_people') 
> >      People = Base.classes.cb_people 
> > 
> > 
> > Then I need to register the class People on graphene like this: 
> > 
> > 
> > @schema.register 
> > class People(SQLAlchemyNode): 
> >      class Meta: 
> >           model = PeopleModel 
> > 
> > 
> > which is not correct. When I run the function init_db(), I got the error 
> > message: 
> > 
> > 
> > File 
> > "/Users/dennisliu/Documents/CrunchbaseFAQ/flask_sqlalchemy/schema.py", 
> > line 12, in <module> 
> > 
> >      class People(SQLAlchemyNode): 
> > 
> >    File 
> > 
> "/usr/local/lib/python2.7/site-packages/graphene/core/classtypes/base.py", 
> > line 31, in __new__ 
> > 
> >      return mcs.construct(new_class, bases, attrs) 
> > 
> >    File 
> > 
> "/usr/local/lib/python2.7/site-packages/graphene/contrib/sqlalchemy/types.py",
>  
>
> > line 57, in construct 
> > 
> >      cls.construct_fields() 
> > 
> >    File 
> > 
> "/usr/local/lib/python2.7/site-packages/graphene/contrib/sqlalchemy/types.py",
>  
>
> > line 22, in construct_fields 
> > 
> >      inspected_model = sqlalchemyinspect(cls._meta.model) 
> > 
> >    File "build/bdist.macosx-10.11-x86_64/egg/sqlalchemy/inspection.py", 
> > line 75, in inspect 
> > 
> > sqlalchemy.exc.NoInspectionAvailable: No inspection system is available 
> > for object of type <class 
> 'sqlalchemy.ext.declarative.api.DeclarativeMeta'> 
> > 
> > 
> > 
> > Is there anyway to solve this problem? 
> > 
> > Thank you so much! 
> > 
> > 
> > 
> > Best, 
> > 
> > Bangrui 
> > 
> > 
> > 
> > -- 
> > 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 [email protected] <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > To post to this group, send email to [email protected] 
> <javascript:> 
> > <mailto:[email protected] <javascript:>>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to