FieldDoesNotExist: ManyToManyField does not have a field named None

I have two models in Django 1.8.8:

class Company(models.Model): name = models.CharField(max_length=200) members = models.ManyToManyField(User) 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) 

and when i do in the template

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

I sometimes (accidentally after reloading several pages) get a very strange error:

 FieldDoesNotExist: Company_members has no field named None 

I also use sqlite3 database. Anyone have an idea where the problem is?

+5
source share
1 answer

There are supported duplicates in the database.

You can check by specifying all the elements in the model using:

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

To avoid this, be sure to set unique = True.

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

Source: https://habr.com/ru/post/1245070/


All Articles