Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:17:57+00:00 2026-06-12T19:17:57+00:00

I need to create an SQLAlchemy version of a linked list. It’s actually more

  • 0

I need to create an SQLAlchemy version of a linked list. It’s actually more complex than that, but it boils down to this:

I need a one-to-one, self-referential, bidirectional relationship in a class. Every element may only have a single parent or none at all, and up to one child.

I simplified my class so it looks like this:

class Node(declarative_base()):
    __tablename__ = 'nodes'

    id = Column(Integer, Sequence('nodes_id_seq'), primary_key=True, autoincrement=True)
    value = Column(Integer)
    prev_node_id = Column(Integer, ForeignKey('nodes.id'))
    next = relationship('Node', uselist=False, backref=backref('prev', uselist=False))

However, when I try to create one, it throws an exception:

>>> Node()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<string>", line 2, in __init__
  File "sqlalchemy\orm\instrumentation.py", line 309, in _new_state_if_none
    state = self._state_constructor(instance, self)

[...]

  File "sqlalchemy\orm\properties.py", line 1418, in _generate_backref
    self._add_reverse_property(self.back_populates)
  File "sqlalchemy\orm\properties.py", line 871, in _add_reverse_property
    % (other, self, self.direction))
ArgumentError: Node.next and back-reference Node.prev are both of the same direction <symbol 'ONETOMANY>.  Did you mean to set remote_side on the many-to-one side ?

What am I missing here? Google search got me absolutely nowhere… :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:17:58+00:00Added an answer on June 12, 2026 at 7:17 pm

    As exception says you need to set remote_side keyword for relationship. Otherwise sqlalchemy cannot select reference direction.

    class Node(declarative_base()):
        ...
        prev = relationship(
            'Node',
            uselist=False,
            remote_side=[id],
            backref=backref('next', uselist=False)
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need create a list of RadioButtons, but if I try to do it
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
We have a need to create SQLAlchemy classes to access multiple external data sources
I need to create a project that has a web frontend to manage synchronous
My Case: I'm working on a system that will need to create various X12
I need to create a BEFORE INSERT trigger in SQLAlchemy: DELIMITER | CREATE TRIGGER
I need create custom tabbar with super class UITabBarController. But i don,t know how
I need create a SQL Server stored procedure that does the following: Take an
How create a link_to_remote in a jQuery script where url need a parameter that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.