你好 Django 重命名我的应用程序的模型
Hello Django renames the model of my app
打错字后将 pricing 打错为 prising
我删除了应用程序,删除了数据库中的表,然后让新应用程序从旧应用程序复制了 models.py
,我做了备份,那么这里的错误仍然存在是管理面板
这里是 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)
和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)
删除迁移文件夹后尝试此命令:
Python manage.py 南瓜迁移
然后重新运行你的迁移:
python manage.py makemigrations appname
python manage.py migrate
如果这不起作用,则删除您的数据库(如果它是 Sqlite),然后重新运行 您的迁移。
再次为该应用重新运行迁移。
python manage.py makemigrations <app>
python manage.py migrate
将解决问题。
打错字后将 pricing 打错为 prising
我删除了应用程序,删除了数据库中的表,然后让新应用程序从旧应用程序复制了 models.py
,我做了备份,那么这里的错误仍然存在是管理面板
这里是 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)
和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)
删除迁移文件夹后尝试此命令:
Python manage.py 南瓜迁移
然后重新运行你的迁移:
python manage.py makemigrations appname
python manage.py migrate
如果这不起作用,则删除您的数据库(如果它是 Sqlite),然后重新运行 您的迁移。
再次为该应用重新运行迁移。
python manage.py makemigrations <app>
python manage.py migrate
将解决问题。