编程错误:关系“ first_app_people”不存在第1行:从“ first_app_people”中选择COUNT(*)AS“ __count”

时间:2020-03-22 07:18:46

标签: python django

我正在尝试在heroku上部署django应用程序。但是有错误我不明白这是什么类型的错误,请帮助解决此错误: 编程错误:关系“ first_app_people”不存在第1行:从“ first_app_people”选择SELECT COUNT(*)AS“ __count”

models.py

class People(models.Model):
  name = models.CharField(max_length=220)
  slug = models.SlugField(unique=True)
  money = models.IntegerField()
  status = models.CharField(max_length=120, null=True, choices=Status)
  date = models.DateTimeField(default=datetime.datetime.now)

  def __str__(self):
    return self.name

  def get_absolute_url(self, *args, **kwargs):
    return reverse("first_app:detail", kwargs={"slug": self.slug})

views.py

from django.shortcuts import render, get_object_or_404, redirect
from .models import People
from .forms import PeoplesForm
def home_page(request):
  form = People.objects.all()
  stock = form.count()
  sell = form.filter(status='Fowara_Chowk').count()
  sold = form.filter(status='Station').count()

  context = {
    'form': form,
    'stock': stock,
    'sold': sold,
    'sell': sell,
  }
  return render(request, 'index.html', context)

def create_view(request):
  form = PeoplesForm(request.POST or None)
  if request.method == "POST":
    if form.is_valid():
        form.save()
        return redirect('/')
 context = {
    'form': form
  }
  return render(request, 'create.html', context)


def detail_view(request, slug):
   form = get_object_or_404(People, slug=slug)
  context = {
   'form': form
   }
  return render(request, 'detail.html', context)

def update_view(request, slug):
  form = People.objects.get(slug=slug)
  update_form = PeoplesForm(instance=form)
  if request.method == "POST":
    update_form = PeoplesForm(request.POST or None, instance=form)
    if update_form.is_valid():
        update_form.save()
        return redirect('/')
  context = {
    'form': update_form,
 }
return render(request, 'update.html', context)


def delete_view(request, slug):
  form = People.objects.get(slug=slug)
  if request.method == "POST":
    form.delete()
    return redirect('/')
  context = {
    'form': form,
    }
  return render(request, 'delete.html', context)

settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'first_app',
'crispy_forms',]`


     CRISPY_TEMPLATE_PACK = 'bootstrap4'
     MIDDLEWARE = [
         'django.middleware.security.SecurityMiddleware',
         'django.contrib.sessions.middleware.SessionMiddleware',
          'django.middleware.common.CommonMiddleware',
          'django.middleware.csrf.CsrfViewMiddleware',
         'django.contrib.auth.middleware.AuthenticationMiddleware',
         'django.contrib.messages.middleware.MessageMiddleware',
         'django.middleware.clickjacking.XFrameOptionsMiddleware',]


     ROOT_URLCONF = 'mysite.urls'



   DATABASES = {
       'default': {
           'ENGINE': 'django.db.backends.sqlite3',
           'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
               }
           }

0 个答案:

没有答案