Psycopg2.errors.UndefinedTable: relation "committees_setting" does not exist

Error:

ProgrammingError at /admin/committees/setting/
relation "committees_setting" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "committees_setting"
                                          ^
Request Method: GET
Request URL:    http://localhost:8000/admin/committees/setting/
Django Version: 4.0.8
Exception Type: ProgrammingError
Exception Value:    
relation "committees_setting" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "committees_setting"
                                          ^
Exception Location: /usr/local/lib/python3.8/site-packages/django/db/backends/utils.py, line 89, in _execute
Python Executable:  /usr/local/bin/python
Python Version: 3.8.17
Python Path:    
['/app',
 '/app',
 '/usr/local/lib/python38.zip',
 '/usr/local/lib/python3.8',
 '/usr/local/lib/python3.8/lib-dynload',
 '/usr/local/lib/python3.8/site-packages',
 '/app/administration',
 '/app/administration']

My models:

Settings:

"""Settings Committees models"""


# Django
from django.db import models

# Models
from administration.utils.models import BaseModel

# Exceptions
from administration.committees.exceptions import (
    SettingsImproperlyConfigured,
)


class Setting(BaseModel):
    """
    Settings Committees model

    A Settings Committees Model contains business information about the committee.
    """

    committee = models.OneToOneField(
        "committees.Committee",
        on_delete=models.CASCADE,
        related_name="settings"
    )

    settings = models.JSONField()

    def __str__(self):
        """Return committee name"""
        return f"{self.committee}' settings"

    def get_setting(self, key, default=False):
        """Return dynamic key setting"""

        return self.settings.get(key, default)

    def late_fee_settings(self):
        """Return late fee setting"""

        late_fee_settings = self.settings.get("late_fee", False)
        if not late_fee_settings:
            raise SettingsImproperlyConfigured("late_fee not fount")
        return late_fee_settings

    def late_fee_is_active(self):
        """Return late fee setting"""

        late_fee_settings = self.late_fee_settings()
        return late_fee_settings.get("active", False)

    def late_fee_percentage(self):
        """Return late fee setting"""

        late_fee_settings = self.late_fee_settings()
        late_fee_percentage = late_fee_settings.get("percentage", False)
        if not late_fee_percentage:
            raise SettingsImproperlyConfigured("late fee percentage not fount")
        return late_fee_percentage

    def late_fee_has_penalty_fee(self):
        """Return late fee setting"""

        late_fee_settings = self.late_fee_settings()
        return late_fee_settings.get("has_penalty_fee", False)

    def penalty_fee_settings(self):
        """Return penalty fee setting"""

        penalty_fee_settings = self.settings.get("penalty_fee", False)
        if not penalty_fee_settings:
            raise SettingsImproperlyConfigured("penalty_fee not fount")
        return penalty_fee_settings

    def penalty_fee_percentage(self):
        """Return penalty fee setting"""

        penalty_fee_settings = self.penalty_fee_settings()
        penalty_fee_percentage = penalty_fee_settings.get("percentage", False)
        if not penalty_fee_percentage:
            raise SettingsImproperlyConfigured("penalty fee percentage not fount")
        return penalty_fee_percentage

    def debt_fee_settings(self):
        """Return debt fee setting"""

        debt_fee_settings = self.settings.get("debt_fee", False)
        if not debt_fee_settings:
            raise SettingsImproperlyConfigured("debt_fee not fount")
        return debt_fee_settings

    def debt_fee_percentage(self):
        """Return debt fee setting"""

        debt_fee_settings = self.debt_fee_settings()
        debt_fee_percentage = debt_fee_settings.get("percentage", False)
        if not debt_fee_percentage:
            raise SettingsImproperlyConfigured("debt fee percentage not fount")
        return debt_fee_percentage



Committees:


"""Committees models"""


# Django
from django.db import models
from django.conf import settings

# Exceptions
from administration.committees.exceptions import (
    SettingNotFound,
)

# Models
from administration.utils.models import BaseModel
from .settings import Setting


class CommitteeManager(models.Manager):
    """Committee Manager"""

    def get_settings(self, committee_id):
        """Get committee settings by id"""
        try:
            return Setting.objects.get(committee__id=committee_id)
        except Setting.DoesNotExist as exc:
            raise SettingNotFound('El consorcio no cuenta con una configuracion') from exc


class Committee(BaseModel):
    """
    Committees model

    A Committees Model is in charge of manage a Building.
    """

    building = models.OneToOneField("buildings.Building", on_delete=models.CASCADE)

    name = models.CharField("committee name", max_length=150, blank=False)

    slug_name = models.SlugField(unique=True, max_length=50, blank=False)

    nickname = models.SlugField(unique=True, max_length=16, blank=False)

    admins = models.ManyToManyField(
        settings.AUTH_USER_MODEL,
        limit_choices_to={'is_staff': True},
        related_name="committees",
        blank=True
    )

    objects = CommitteeManager()

    def __str__(self):
        """Return committee name"""
        return str(self.name)

Additional Info:

  • I am using the admin console where almost all other collections are accessible without any issues.

Still have the same issue, any ideas on what could be wrong?

Things I have already tried:

I created migrations, many of them. I fist setup a default value for "committee" for the existent objects in the DB, as that didnt work, I deleted all the data from the collection and it turned out there was zero:


In [1]: from administration.committees.models import Setting
   ...: Setting.objects.all().delete()
   ...: 
Out[1]: (0, {})

In [2]:

I also searched through the questions already answered here but most have the same solution of making migrations which I have already done.

Вернуться на верх