Re: [sqlalchemy] reflecting mysql view

2019-02-14 Thread christian . tremel
Simon, thank you for your kind help. working excerpt: Base = declarative_base() engine = create_engine(app.config.get('SQLALCHEMY_DATABASE_URI')) metadata = MetaData(bind=engine) Base.metadata = metadata # load tables metadata.reflect(autoload=True) # load view, as standard reflection ignores

Re: [sqlalchemy] reflecting mysql view

2019-02-14 Thread Simon King
There are a few different points to make here: 1. SQLAlchemy requires mapped classes to have a primary key defined. This is because an instance of the mapped class corresponds to a row in the database. In order to make changes to that row (UPDATE, DELETE etc.), SQLAlchemy needs to be able to

Re: [sqlalchemy] reflecting mysql view

2019-02-14 Thread christian . tremel
i fiddled around with this. here are some interessting perceptions. defining the primary_key manually yields this, which is totally irrational to me. the missing view that i am after is already defined somewhere? p... >>> my_view = Table("web_view", metadata, Column("NODE_ID", Integer,

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread christian . tremel
maybe a "primary key" issue? from the docs: sually, it’s desired to have at least a primary key constraint when reflecting a view, if not foreign keys as well. View reflection doesn’t extrapolate these constraints. Use the “override” technique for this, specifying explicitly those columns

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread christian . tremel
ok, so we are back to the central question. the output below indictates that only "tables" are reflected and "views" are ignored. i like to think i am not the first who wants to use mysql views with sqla? is this really such a difficult task? >>> print(Base.classes.keys()) ['attribs',

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread Simon King
On Wed, Feb 13, 2019 at 3:22 PM Simon King wrote: > > On Wed, Feb 13, 2019 at 3:13 PM wrote: > > > > did not work out very well,...god, this stuff gives some good headache! > > > > >>> from sqlalchemy.ext.automap import automap_base > > >>> Base = automap_base(metadata=metadata) > > >>>

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread Simon King
On Wed, Feb 13, 2019 at 3:13 PM wrote: > > did not work out very well,...god, this stuff gives some good headache! > > >>> from sqlalchemy.ext.automap import automap_base > >>> Base = automap_base(metadata=metadata) > >>> Base.prepare() > >>> WebView = Base.classes.web_view > Traceback (most

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread christian . tremel
did not work out very well,...god, this stuff gives some good headache! >>> from sqlalchemy.ext.automap import automap_base >>> Base = automap_base(metadata=metadata) >>> Base.prepare() >>> WebView = Base.classes.web_view Traceback (most recent call last): File "", line 1, in File

Re: [sqlalchemy] reflecting mysql view

2019-02-13 Thread Simon King
It looks like you are mixing up Table objects (which are part of SQLAlchemy Core) with mapped classes (part of SQLAlchemy ORM). The objects in metadata.tables are instances of the Table class, and each correspond to a table or view in the database. The ORM allows you to define classes which are

[sqlalchemy] reflecting mysql view

2019-02-13 Thread christian . tremel
i already spent 3 days trying to map one stupid mysql view and i cant get it to work. in the python interpreter it works... Python 2.7.5 (default, May 31 2018, 09:45:54) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information.