django AttributeError: 'tuple' object has no attribute 'rsplit'


Running python check throws an error AttributeError: 'tuple' object has no attribute 'rsplit'.

Traceback (most recent call last):
  File "/home/mieltn/django_projects/batch/", line 22, in <module>
  File "/home/mieltn/django_projects/batch/", line 18, in main
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/core/management/", line 419, in execute_from_command_line
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/core/management/", line 395, in execute
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/", line 24, in setup
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/apps/", line 114, in populate
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/apps/", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/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 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/mieltn/django_projects/batch/unesco/", line 4, in <module>
    class Category(models.Model):
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/db/models/", line 320, in __new__
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/db/models/", line 333, in _prepare
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/db/models/", line 285, in _prepare
    pk_class = self._get_default_pk_class()
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/db/models/", line 238, in _get_default_pk_class
    pk_class = import_string(pk_class_path)
  File "/home/mieltn/.virtualenvs/django3/lib/python3.9/site-packages/django/utils/", line 13, in import_string
    module_path, class_name = dotted_path.rsplit('.', 1)
AttributeError: 'tuple' object has no attribute 'rsplit'

I saw similar thread about such error and it doesn’t seem to be the case. The problem is supposedly connected with, because when the models file remains empty everything works fine. When I add

from django.db import models

class Category(models.Model):
    name = models.CharField(max_length=128)

check crashes.

I guess, there might be a silly mistake or mistype, I’m failing to capture. Thanks in advance.

EDIT: looks as following

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_w_1zo)mcg((=iko!2-1vqjf)dme9#[email protected]%&!4'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition



ROOT_URLCONF = 'batch.urls'

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

WSGI_APPLICATION = 'batch.wsgi.application'

# Database

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',

# Password validation

        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

# Internationalization



USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

unesco/ has only UnescoConfig

from django.apps import AppConfig

class UnescoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField',
    name = 'unesco'


Django provides DEFAULT_AUTO_FIELD which is a default primary key field type to use for models that don’t have a field with primary_key=True. This can also be override on the app level using
AppConfig.default_auto_field. Since you override default_auto_field field on the app level it gets priority compared to settings.DEFAULT_AUTO_FIELD.

Django then try to import this string dynamically. As part of it, it then try to split the string into module_path and class_name.

So answering your question, the issue is here

from django.apps import AppConfig

class UnescoConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField',
    name = 'unesco'

This will treat default_auto_field as tuple(Note the trailing comma) instead of a string.

>>> myfield = 'django.db.models.BigAutoField',
>>> type(myfield)
<class 'tuple'>
>>> module_path, class_name = myfield.rsplit('.', 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'rsplit'

Answered By – Abdul Niyas P M

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published