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
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
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,
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
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',
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)
> > >>>
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
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
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
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.
10 matches
Mail list logo