Thank you very much! It is working now.

My mistake was to use @declared_attr to create a unique sequence per 
mapper, and that was not working of course.

среда, 25 апреля 2018 г., 22:04:58 UTC+3 пользователь Stanislav Lobanov 
написал:
>
> Hello!
>
> I have a base model class with "id" field, which is primary key and also 
> not nullable. It does not have autoincrement feature, but uses custom 
> sequence manually to assign it's value.
>
> There are standard on table / sequence naming:
>
> class Base:
>     id = Column(Integer, primary_key=True, nullable=False)
>
>
> class A(Base):
>     __tablename__ = 'a'
>
>
> class B(Base):
>     __tablename__ = 'b'
>
>
>
> What i need is to do two things:
>
> 1. Automatically add sequences to A and B tables (in ORM context, 
> mappers), named "__tablename__$seq" -> 'a$seq' and 'b$seq'. By sequences i 
> mean an attribute of type Sequence.
> 2. Somehow associate it with "id" column, so the sequence can be 
> automatically created after "create_all()" function call.
>
> I tried to use this approach: Associating a Sequence as the Server Side 
> Default (
> http://docs.sqlalchemy.org/en/latest/core/defaults.html#associating-a-sequence-as-the-server-side-default
> )
> but did not succeed because sequence name is always hardcoded in base 
> class, but in my case it must be autogenerated based on custom naming rule.
>
> I have spent four hours trying different techniques but did not succeed 
> with this.
>
> Thanks!
>

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

Reply via email to