Class with multiple foreign key references to the same table throws error
See original GitHub issueAfter upgrading this class throws an error:
class InvHostDr(BaseModel):
comment = TextField()
primary_array = ForeignKeyField(
db_column='primary_array_id', rel_model=InvArray)
primary_host = ForeignKeyField(
db_column='primary_host_id', rel_model=InvHost)
primary_project_host = ForeignKeyField(
db_column='primary_project_host_id', rel_model=PrjProjectHost)
primary_shadowimage = TextField()
primary_volumes = TextField()
replication_group = CharField()
secondary_array = ForeignKeyField(
db_column='secondary_array_id', rel_model=InvArray)
secondary_host = ForeignKeyField(
db_column='secondary_host_id', rel_model=InvHost)
secondary_project_host = ForeignKeyField(
db_column='secondary_project_host_id', rel_model=PrjProjectHost)
secondary_shadowimage = TextField()
secondary_volumes = TextField()
class Meta:
db_table = 'inv_host_dr'
Here’s the error:
AttributeError: Foreign key: invhostdr.primary_array related name "invhostdr_set" collision with foreign key using same related_name.
I’m not even calling this class in the code, it errors when the module is initialized.
Issue Analytics
- State:
- Created 10 years ago
- Comments:13 (5 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 >How to Add Multiple Foreign Keys to Same Table and Not Get ...
Start by creating tables without any foreign keys. If you try to create tables with foreign keys that reference other tables that are...
Read more >3 common foreign key mistakes (and how to avoid them)
1. Mismatched data types ... When you're using a foreign key to reference a column in another table, the datatypes of both tables...
Read more >13.1.18.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
A foreign key constraint is defined on the child table. ... Foreign Key Errors ... One foreign key references a two-column index in...
Read more >Changing Foreign Keys and Navigations - EF Core
Relationships in an Entity Framework Core (EF Core) model are represented using foreign keys (FKs). An FK consists of one or more properties ......
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
Charles,
I’m facing the same problem.
Here a simple example to reproduce:
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.
Ok, I resolved this, thanks.