[Fixed]-Django makemigrations AttributeError: 'str' object has no attribute '_meta'

13👍

There doesn’t seem to be a class named ImagePerson in that file which is what you are setting the through (the through table) to be in the M2M on Person.

3👍

Indentation problem on your Crew class?
Your str method here seems to be defined on the Meta:

class Crew(models.Model):
    name = models.CharField(max_length=256)
    members = models.ManyToManyField(
        'Profile',
        through='MovieCrew',
        through_fields=('crew', 'profile'),
    )

    class Meta:
        db_table = 'Crew'


        def __str__(self):
            return '{0}: {1}'.format(self.__class__.__name__, self.name)

    def __repr__(self):
        return self.__str__()

Is that really what you’re after?

2👍

make sure you did python manage.py makemigrations and python manage.py migrate

if you already did it then check

in serializers.py

class Meta:
    model = 'bla bla' 
    fields = '__all__'

I got this error when i wrote model name in string ('') if you did same mistake then check and remove ''

1👍

For some people getting this error, don’t forget to add a newly created app into Django’s INSTALLED_APPS for your ManyToMany‘s through= intermediary model to be recognized.

0👍

If you get this error when registering your model in the admin.py then it is because of the follow:

admin.site.register('Post')

and replace it with

admin.site.register(Post)

TLDR: get rid of the the quotations in the model name

Leave a comment