We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have models:
import uuid from tortoise import fields, models class BaseModel(models.Model): id = fields.UUIDField(pk=True, editable=False, default=uuid.uuid4) created_at = fields.DatetimeField(auto_now_add=True) class Meta: abstract = True def __str__(self): pass class User(BaseModel): first_name = fields.CharField(max_length=150) last_name = fields.CharField(max_length=150) username = fields.CharField(max_length=150) tg_id = fields.CharField(max_length=150) class Check(BaseModel): user = fields.ForeignKeyField( 'models.User', related_name='checks', null=True, on_delete=fields.SET_NULL, default=None, to_field="id" ) lg = fields.CharField(max_length=150, unique=True) class Product(BaseModel): name = fields.CharField(max_length=150) count = fields.IntField() check = fields.ForeignKeyField( 'models.Check', related_name='products', null=True, on_delete=fields.SET_NULL, default=None )
Code above issue:
And when I change name of field check in Product model to any other, everything work.
check
Product
E.g.: bill = fields.ForeignKeyField( 'models.Check', related_name='products', null=True, on_delete=fields.SET_NULL, default=None )
bill = fields.ForeignKeyField( 'models.Check', related_name='products', null=True, on_delete=fields.SET_NULL, default=None )
What's wrong I do?
The text was updated successfully, but these errors were encountered:
I speculate that it may be a collision of the field name 'check' with a method of the model bearing the same name.
This has happened to me in the past and I have not found a better solution other than to change the field name or prefix it with a _ (undescore)
EDIT: related to #1559
Sorry, something went wrong.
Renamed Model.check method (#1559) (#1550)
a5be9b6
Your example should work in 0.21.0 as check is not reserved anymore
No branches or pull requests
I have models:
Code above issue:
And when I change name of field
check
inProduct
model to any other, everything work.E.g.:
bill = fields.ForeignKeyField( 'models.Check', related_name='products', null=True, on_delete=fields.SET_NULL, default=None )
What's wrong I do?
The text was updated successfully, but these errors were encountered: