I am working on an app using python3 and SqlAlchemy for SQLite3 database
management. I have some tables that have a Many to Many relationship. I've
created an association table to handle this relationship.
Class Machine(Base):
__tablename__ 'machine'
machine_ID = Column(Integer, primary_key=True)
etc...
Class Options(Base):
__tableName__ 'options'
options_ID = Column(Integer, primary_key=True)
etc...
The association table
Machine_Options = table('machine_options', Base.metadata,
Column('machine_FK', Integer, ForeignKey('machine.machine_ID'),
primary_key=True),
Column('options_FK',Integer, ForeignKey('options.options_ID'),
primary_key=True))
All the items for the Machine and Options are inserted independently. When
I want to associate a machine with an option I use an append query which
works very well.
My problem is when I want to break this association between a machine and
an option. I have tried a direct row deletion from the association table
using a FILTER() clause on the machine_FK and the options_FK but SqlAlchemy
gives me an error informing me that 'Machine_Options' table has no field
'machine_FK'. It seems that SqlAlchemy does not map association tables. I
have tried to remove the row from 'Machine_Options' indirectly using joins
with the machine and options table but received another error that I can
not delete or update using joins.
I am looking for the code to only delete a row from the association table
without affecting the original machine or options table.
So far my internet search has been fruitless.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/60cb5a82-ca33-46c9-bf1e-b70deb82b485o%40googlegroups.com.