[Fixed]-FieldDoesNotExist: ManyToManyField has no field named None

1👍

This is most probbly the related django ticket you should check https://code.djangoproject.com/ticket/24513

And this issue could be somehow related though not 100% https://github.com/jet-admin/jet-django/issues/7

You might get some insight reading the threads.

👤auvipy

0👍

If you want to access a ForeignKey field from an instance you can not access it directly as you did here

{% for user in current_folder.company.members.all %}

ForeignKey field is a company so it should be

current_folder.company_set()

Note: ForeignKey returns a set of objects. In your case a set of companies. That’s why it returns FieldDoesNotExist

-1👍

In ManyToManyFields you must add the related_name parameter if you want to access the related objects. So for this case, it should be like this:

class Company(models.Model):
    name = models.CharField(max_length=200)
    members = models.ManyToManyField(User, related_name='members')
class Folder(models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(null=True, blank=True)
    company = models.ForeignKey(Company, null=True, blank=True)
    parent = models.ForeignKey("Folder", null=True, blank=True)

-1👍

try adding null and blank field

members = models.ManyToManyField(user, blank=True, null=True)
👤vineet

-2👍

There is propably duplicate items in the datebase.

You can check by listing all items in model using:

YourModel.objects.values_list('id', 'name')

To avoid it make sure to set unique=True.

name = models.CharField(max_length=200, unique=True)

Leave a comment