Home > Software design >  Why leads deletion of UUIDField to Django SystemCheckError
Why leads deletion of UUIDField to Django SystemCheckError

Time:04-10

I've been building a Django website and included a UUID field "customer_id" in my initial "Customer" model. Finally, I decided to drop it. But when I try to delete it from my models.py, Django throws

SystemCheckError: System check identified some issues:

ERRORS:
<class 'accounts.admin.CustomerAdmin'>: (admin.E035) The value of 'readonly_fields[1]' is not a callable, an attribute of 'CustomerAdmin', or an attribute of 'accounts.Customer'.

Here is the code of models.py

    from django.db import models
    import uuid
    
    # Create a base model to make sure we keep track of creation and edits
    class ModelBaseClass(models.Model):
        date_created = models.DateTimeField(auto_now_add=True, null=True)
        date_modified = models.DateTimeField(auto_now=True, null=True)
    
        class Meta:
            abstract = True
    
    # Create your models here.
    class Customer(ModelBaseClass):
        customer_id = models.UUIDField(default=uuid.uuid4, #this is the field i try to drop
                                   editable=False, 
                                   unique=True)
        name = models.CharField(max_length=200, null=True)
        email = models.CharField(max_length=200, null=True)
            
        def __str__(self):
            return self.name

What I tried so far:

I suspect that this could be related to existing data or some other dependencies. So...

  1. I deleted the sqlite database, deleted all migration files and ran "python manage.py makemigrations" and "python manage.py migrate".
  2. I ran python manage.py flush.
  3. I also tried to change the editable=False to editable=True and migrate before dropping, but it didn't change anything.

It's perhaps also worth mentioning that my "Customer" model a relation to another model.

Could someone explain me why Django is preventing me from deleting this field and how to resolve this?

Thanks! :)

CodePudding user response:

Could someone explain me what's going on and how to resolve this?

As the error says, you have a model admin named CustomerAdmin. Indeed:

<class 'accounts.admin.CustomerAdmin'>: (admin.E035) The value of 'readonly_fields[1]' is not a callable, an attribute of 'CustomerAdmin', or an attribute of 'accounts.Customer'.

For the readonly_fields, it lists the customer_id, but since that field is no longer available, it raises the error.

  • Related