tortoise / tortoise/tortoise-orm

[QUESTION] backward relation duplicates ?

Open
#509 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

I have the following models:

`

class PerfilDoctor(models.Model):

     id = fields.UUIDField(pk=True)
     usuario = fields.OneToOneField('models.UserModel', related_name="user_profile", on_delete=fields.CASCADE)
     descripcion = fields.CharField(max_length=500)

class Clinica(models.Model):

    id = fields.UUIDField(pk=True)
    cliente = fields.ForeignKeyField('models.UserModel', related_name="cliente_clinica", on_delete=fields.CASCADE)
    nombre = fields.CharField(max_length=50)


class Puntuacion(models.Model):

     id = fields.UUIDField(pk=True)
     doctor = fields.OneToOneField('models.PerfilDoctor', related_name="doctor_puntuacion", on_delete=fields.CASCADE, null=True)
    clinica = fields.OneToOneField('models.Clinica', related_name="clinica_puntuacion", on_delete=fields.CASCADE, null=True)

And when I run the code gives me this error:

tortoise.exceptions.ConfigurationError: backward relation "doctor_puntuacion" duplicates in model PerfilDoctor

Any idea why it's happening ? thank for your help!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PerfilDoctor, Clinica, and Puntuacion model definitions shown in the issue and trace how their related_name values are registered. Reproduce the ConfigurationError using this model setup; done should be a clear explanation of why doctor_puntuacion is duplicated and whether the behavior requires a project change.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.