AttributeError: type object 'Profile' has no attribute 'objects'

\Desktop\JMS> py manage.py createsuperuser
Email: emmasasu1670@gmail.com
Username: Emmanuel
Password: 
Password (again): 
Traceback (most recent call last):
  File "C:\Users\Emmanuel_coder\Desktop\JMS\manage.py", line 22, in <module>
    main()
  File "C:\Users\Emmanuel_coder\Desktop\JMS\manage.py", line 18, in main   
    execute_from_command_line(sys.argv)
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\__init__.py", line 436, in execute   
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv 
    self.execute(*args, **cmd_options)
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 90, in execute     
    return super().execute(*args, **options)      
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\base.py", line 459, in execute       
    output = self.handle(*args, **options)        
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 239, in handle     
    self.UserModel._default_manager.db_manager(database).create_superuser( 
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\models.py", line 173, in create_superuser
    return self._create_user(username, email, password, **extra_fields)    
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\models.py", line 156, in _create_user   
    user.save(using=self._db)
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\auth\base_user.py", line 62, in save
    super().save(*args, **kwargs)
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 891, in save
    self.save_base(
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 1012, in save_base
    post_save.send(      
  File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\dispatch\dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
ths\models.py", line 78, in create_user_profile
    Profile.objects.createths\models.py", line 78, in create_user_profile     
    Profile.objects.create(user=instance)
    ^^^^^^^^^^^^^^^       
AttributeError: type object 'Profile' has no attribute 'objects'

why is this happening

Please post the complete view causing this message (create_user_profile) and the complete definition of your Profile model.

Also, when posting code, templates, error messages or other preformatted text here, enclose it between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. (This forces the forum software to keep your code properly formatted.) I’ve taken the liberty of editing your original post for this.

1 Like

from django.contrib import admin
from userauths.models import User, Profile

class UserAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘username’,]
list_display = [‘username’, ‘full_name’, ‘email’, ‘phone’, ‘gender’,]

class ProfileAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘user_username’,]
list_display = [‘username’, ‘user’, ‘verified’,]

admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)

that is the models.py

PS C:\Users\Emmanuel_coder\Desktop\JMS> py manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1075, in _bootstrap_inner
self.run()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\threading.py”, line 1012, in run
self.target(*self.args, **self.kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\commands\runserver.py”, line 126, in inner_run
autoreload.raise_last_exception()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 87, in raise_last_exception
raise exception[1]
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management_init
.py", line 394, in execute
autoreload.check_errors(django.setup)()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django_init
.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\apps\registry.py”, line 124, in populate
app_config.ready()
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\apps.py”, line 27, in ready
self.module.autodiscover()
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin_init
.py", line 52, in autodiscover
autodiscover_modules(“admin”, register_to=site)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\module_loading.py”, line 58, in autodiscover_modules
import_module(“%s.%s” % (app_config.name, module_to_search))
File "C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\importlib_init
.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 1387, in _gcd_import
File “”, line 1360, in _find_and_load
File “”, line 1331, in _find_and_load_unlocked
File “”, line 935, in _load_unlocked
File “”, line 995, in exec_module
File “”, line 488, in _call_with_frames_removed
File “C:\Users\Emmanuel_coder\Desktop\JMS\userauths\admin.py”, line 14, in
admin.site.register(Profile, ProfileAdmin)
File “C:\Users\Emmanuel_coder\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\contrib\admin\sites.py”, line 110, in register
for model in model_or_iterable:
^^^^^^^^^^^^^^^^^
TypeError: ‘type’ object is not iterable

That looks like your admin.py, not your models.py.

And again, please use the three backticks (```) on lines before and after posting code, templates, error messages, and other preformatted text.

pls I don’t understand

Please explain what it is that you don’t understand.

can you explain it well to me

When you are posting code, templates, error messages, tracebacks, or any other preformatted text, surround that text between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code (or template, or error message, or traceback), then another line of ```.
Example: The next line of this post is ```:

# The line above this is ```
def function():
    return None
# The line after this is ```

If you don’t put those lines around your code, it ends up looking like what you’ve got posted - you lose all the indentation, making the code difficult to understand.

The lines of ``` must be on lines by themselves, they must not be part of another line.

okay so please my admin,py where should i put my three bactick helps help to fix this

from cProfile import Profile
from django.contrib import admin
from userauths.models import User, Profile

class UserAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘username’]
list_display = [‘username’, ‘full_name’, ‘email’, ‘phone’, ‘gender’]

class ProfileAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘user_username’,]
list_display = [‘username’, ‘user’, ‘verified’,]

admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)

should i send you my models.py

You need to put ``` on the line before the line from cProfile ... and ``` on the line after the line admin.site.register(Profile, ProfileAdmin)

Note, when you joined the forum, you should have received a message from “Discobot” referencing a tutorial for the forum. I strongly suggest you take that tutorial to learn how to best use this forum.

okay i will learn how to use the forum thank you

‘’'from cProfile import Profile
from django.contrib import admin
from userauths.models import User, Profile

class UserAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘username’]
list_display = [‘username’, ‘full_name’, ‘email’, ‘phone’, ‘gender’]

class ProfileAdmin(admin.ModelAdmin):
search_fields = [‘full_name’, ‘user_username’]
list_display = [‘username’, ‘user’, ‘verified’]

admin.site.register(User, UserAdmin)
admin.site.register(Profile, ProfileAdmin)‘’’

Please see my reply at AttributeError: type object 'Profile' has no attribute 'objects' - #7 by KenWhitesell and at AttributeError: type object 'Profile' has no attribute 'objects' - #11 by KenWhitesell

yes seen that it works let me create my superuser and see if it will also works

still not working

AttributeError: type object ‘Profile’ has no attribute ‘objects’