AttributeError with multiple ForeignKeyField to the same table.
See original GitHub issueCharles,
Here a simple example to reproduce:
from peewee import *
class Parent(Model):
name = CharField()
class Student(Model):
name = CharField()
father = ForeignKeyField(Parent)
mother = ForeignKeyField(Parent)
AttributeError: Foreign key: student.mother related name "student_set" collision with foreign key using same related_name.
It seems that peewee tries to make a set with all the references to same table, but there is case where the attributes are different.
Issue Analytics
- State:
- Created 10 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Sqlalchemy error, multiple foreign keys references to the same ...
This works for me in version 1.4: class Message(Base): __tablename__ = "messages" id = sa.Column(sa.Integer, primary_key=True) sender_id ...
Read more >The right way to use a ManyToManyField in Django
To maintain a many-to-many relationship between two tables in a database, the only way is to have a third table which has references...
Read more >Describing Databases with MetaData
MetaData is a container object that keeps together many different features of a database (or multiple databases) being described.
Read more >peewee - Models and Fields - Documentation sets
ForeignKeyField is a special field type that allows one model to reference another. · Foreign keys allow data to be normalized. · If...
Read more >Making queries | Django documentation
To represent database-table data in Python objects, Django uses an ... Updating a ForeignKey field works exactly the same way as saving a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is because there are two foreign keys to the same model on
Student
. Specifyrelated_name
attributes (the backref onParent
):This is a new error that is raised because both parent fks would use the same backref (
student_set
), which is ambiguous.I’ll look into it, but I’m going to go out on a limb and say that
pwiz
does a pretty damn good job at what it does.