Django and Python Error: has no attribute '_meta

I am working on Django for Beginners newsletter project and I have the following error message.
Traceback message:

(.venv) andrewstribling@Andrews-MBP news % python makemigrations accounts
Traceback (most recent call last):
  File "/Users/andrewstribling/Desktop/code/news/", line 22, in <module>
  File "/Users/andrewstribling/Desktop/code/news/", line 18, in main
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/", line 442, in execute_from_command_line
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/core/management/", line 416, in execute
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/", line 24, in setup
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/apps/", line 124, in populate
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/contrib/admin/", line 27, in ready
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/contrib/admin/", line 50, in autodiscover
    autodiscover_modules("admin", register_to=site)
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/utils/", line 58, in autodiscover_modules
    import_module("%s.%s" % (, module_to_search))
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/andrewstribling/Desktop/code/news/accounts/", line 27, in <module>, CustomUserAdmin))
  File "/Users/andrewstribling/Library/Python/3.9/lib/python/site-packages/django/contrib/admin/", line 118, in register
    if model._meta.abstract:
AttributeError: type object 'CustomUserAdmin' has no attribute '_meta'

So the last line there in the traceback that says my class customuser admin says attribute has no meta. I think that makes since because there isn’t a class for Meta specified. So do I just create a Meta class?

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

""" The final step is to update our file since the admin is tightly coupled to the default
User model. We will extend the existing UserAdmin class to use our new CustomUser model.
To control which fields are listed, we use list_display. But to actually edit new custom fields,
like age, we must add fieldsets. And to include a new custom field in the section for creating a
new user we rely on add_fieldsets.""" 
# Register your models here.
from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser

class CustomUserAdmin(UserAdmin):
    add_form = CustomUserCreationForm
    form = CustomUserChangeForm
    model = CustomUser
    list_display = [
    fieldsets = UserAdmin.fieldsets + ((None, {"fields": ("age",)}),)
    add_fieldsets = UserAdmin.add_fieldsets + ((None, {"fields": ("age",)}),), CustomUserAdmin))

I am thinking that all I need to do is create a class Meta. Am I on the right track? Right now I am checking Django Forum and stack overflow for solutions.

Following line in your code is incorect:, CustomUserAdmin))

Epected form is:, CustomUserAdmin)
1 Like

done in by a parentheses!