Search code examples
pythondjangodjango-modelsdjango-admindjango-apps

Hello Django renames the model of my app


After having a typo and mistyped pricing as prising

I've removed the app, deleted the tables in the database then made the new app copied the models.py from the old app, I did a backup, then the error persist here is the admin-panelenter image description here

here is the models.py

class PriceList(models.Model):
    class Meta:
        verbose_name = _("ценоразпис")
        verbose_name_plural = _("ценоразписи")


    name = models.CharField(blank=False, null=False, max_length=300, verbose_name="наименование")
    description = models.CharField(blank=False, null=False, max_length=300, verbose_name="Описание")

    def show_name(self):
        return '{}'.format(self.name)
    def show_description(self):
        return '{}'.format(self.description)
    def __str__(self):
        return '{}'.format(self.name)

class PriceListItem(models.Model):
    class Meta:
        verbose_name = _("елемент от ценоразпис")
        verbose_name_plural = _("елементи от ценоразпис")
        ordering = ['id']

    price_list = models.ForeignKey(PriceList, blank=False, null=False, verbose_name="ценоразпис", on_delete=models.CASCADE)
    title_bg = models.CharField(blank=False, null=False, max_length=200, verbose_name="наименование BG")
    description_bg = models.CharField(blank=False, null=False, max_length=200, verbose_name="Описание BG")
    title_en = models.CharField(blank=False, null=False, max_length=200, verbose_name="наименование EN")
    description_en = models.CharField(blank=False, null=False, max_length=200, verbose_name="Описание EN")
    price_bg = models.DecimalField(blank=False, null=False, decimal_places=PRICE_DECIMAL_PLACES, max_digits=PRICE_DECIMAL_DIGITS, verbose_name="BGN")
    price_en = models.DecimalField(blank=False, null=False, decimal_places=PRICE_DECIMAL_PLACES, max_digits=PRICE_DECIMAL_DIGITS, verbose_name="EUR")

    def __str__(self):
        return '{}'.format(self.id)

and the admin.py

from django.contrib import admin

from pricing.models import PriceList, PriceListItem


class PriceListItemInline(admin.TabularInline):
    model = PriceListItem


class PriceListAdmin(admin.ModelAdmin):
    model = PriceList
    inlines = [PriceListItemInline, ]
    list_display = ('name', 'description')




admin.site.register(PriceList , PriceListAdmin)

Solution

  • Try this command after you've deleted your migrations folder:

    Python manage.py squashmigrations

    Then re-run your migrations:

    python manage.py makemigrations appname
    
    python manage.py migrate
    

    If this doesn't work then delete your db if its Sqlite and then re-run your migrations.