Hey, Ive got this problem here. I will paste in my code too. After looking through the internet, I found this error, but only for custom User models.
In my example I have a simple Comment model:
class Comment(models.Model):
author = models.ForeignKey(User, default=1, on_delete=models.SET_DEFAULT)
published = models.DateField(auto_now_add=True)
hidden = models.BooleanField(default=False)
content = models.TextField()
ref_comments = models.ManyToManyField('self', blank=True, related_name="comment_relation", default=None)
parent = models.ForeignKey('self', default=None, null=True, on_delete=models.SET_DEFAULT)
level = models.SmallIntegerField(default=1)
no_of_reactions = models.IntegerField(default=0)
def delete_tread(self):
self.delete()
orphans = Comment.objects.filter(parent=None)
for com in orphans:
if not com.get_blog() and not com.get_vlog() and not com.get_popPost() and not com.get_article():
com.delete()
def get_article(self):
if self.article_relation.all():
return self.article_relation.all()[0]
else:
return None
def get_blog(self):
if self.blog_relation.all():
return self.blog_relation.all()[0]
else:
return None
def get_vlog(self):
if self.vlog_relation.all():
return self.vlog_relation.all()[0]
else:
return None
def get_popPost(self):
if self.pop_relation.all():
return self.pop_relation.all()[0]
else:
return None
def __str__(self):
return self.content
Error message:
File “/workspaces/coachGu-live/guru/models.py”, line 100, in
class Comment(models.Model):
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/base.py”, line 160, in new
new_class.add_to_class(obj_name, obj)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/base.py”, line 325, in add_to_class
value.contribute_to_class(cls, name)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/fields/related.py”, line 1585, in contribute_to_class
self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/fields/related.py”, line 1052, in create_many_to_many_intermediary_model
lazy_related_operation(set_managed, klass, to_model, name)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/fields/related.py”, line 80, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/fields/related.py”, line 78, in
model_keys = (make_model_tuple(m) for m in models)
File “/usr/local/python/3.10.13/lib/python3.10/site-packages/django/db/models/utils.py”, line 18, in make_model_tuple
raise ValueError(
ValueError: Invalid model reference ‘my.guru.Comment_ref_comments’. String model references must be of the form ‘app_label.ModelName’.
Please help me, and tell if I need to show other code snippets! Thanks