S
S
SHADRIN2020-04-29 02:03:41
Django
SHADRIN, 2020-04-29 02:03:41

I don't understand what Django is asking for?

It was like this
There was a database, I added new columns to it and Django logically began to swear that there were no columns.
I deleted the database and the migration files performed the migration again and now it tells me that there is no table which should not be. What to do?

from django.shortcuts import render
from django.http import Http404, HttpResponseRedirect
from django.http import HttpResponse
from . models import allfilms

def index(request):
  allfilm = allfilms.objects.all()[:21]
  return render(request, 'main/homepage.html', <b>context = {'allfilms' : allfilm}</b>)

I selected a piece without which the page opens well, logically without data.
I have only one allfilms table but it asks for main_allfilms
OperationalError at /
no such table: main_allfilms
Request Method:	GET
Request URL:	http://127.0.0.1:8000/
Django Version:	3.0.5
Exception Type:	OperationalError
Exception Value:	
no such table: main_allfilms
Exception Location:	C:\Users\saxar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 396
Python Executable:	C:\Users\saxar\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version:	3.8.2
Python Path:	
['C:\\Users\\saxar\\OneDrive\\Рабочий стол\\stockfilms\\mysite',
 'C:\\Users\\saxar\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
 'C:\\Users\\saxar\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
 'C:\\Users\\saxar\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
 'C:\\Users\\saxar\\AppData\\Local\\Programs\\Python\\Python38-32',
 'C:\\Users\\saxar\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Server time:	Tue, 28 Apr 2020 22:57:37 +0000


model.py

from django.db import models

class allfilms(models.Model):
  title = models.CharField(max_length = 50)
  img_src = models.TextField()
  genre = models.TextField(max_length = 50)
  description = models.TextField(max_length = 700)
  year = models.TextField(max_length = 50)
  postback = models.TextField()
  postfront = models.TextField()

  def __str__(self):
    return self.title


urls.py
from django.conf.urls import url, include
from . import views
from django.views.generic import ListView, DetailView
from main.models import allfilms

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^$', ListView.as_view(queryset=allfilms.objects.all().order_by("-title")[:21], template_name="main/homepage.html")),
    url(r'^(?P<pk>\d+)$', DetailView.as_view(model = allfilms, template_name="main/post.html"))
    ]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question