[Fixed]-How to Create Custom Permission and Group model in django?

1👍

class Permission(models.Model):
    def __unicode__(self):
        return self.name

    codename = models.CharField(max_length=50, blank=False)
    name = models.CharField(max_length=50, blank=False)

    class Meta:
        db_table = 'auth_permission'

You expect your table to be named auth_permission which is already being used by the Permission model in the django.contrib.auth app. This is why the error says:

django.db.utils.ProgrammingError: relation "auth_permission" already exists

Solution:

  • Choose a different table name
  • Do not specify the table name, then it will be in the form of <app>_<modelclass>
  • Another very bad idea would be to remove the django.contrib.auth from INSTALLED_APPS in settings.py but then you risk breaking a lot of stuff and you probably really don’t want that.
👤masnun

Leave a comment