我已经检查了一些其他类似问题的帖子。我把所有的事都做了... 我尝试删除所有迁移,然后再次迁移。我也选择了syncdb选项。
仍然出现此错误:http://prntscr.com/nxuq1d 没有这样的表。
我正在使用Django 2.5.1版本
编辑:重写类别的拼写错误后,几乎发生了相同的错误。 这次它说:没有这样的专栏:blog_category_id-> http://prntscr.com/nxvv4r
这是代码
models.py
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils.text import slugify
from ckeditor_uploader.fields import RichTextUploadingField
class Category(models.Model):
name = models.CharField(max_length=150)
slug = models.SlugField(max_length=150)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
class Post(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(
help_text="A short label, generally used in URLs.", default='', max_length=100)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
image = models.ImageField(default='default.jpg', upload_to='profile_pics')
content = RichTextUploadingField(blank=True, null=True)
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
class Meta:
ordering = ['-date_posted']
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Post, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('detail', kwargs={'slug': self.slug})
def __str__(self):
return self.title
0001_initial.py ..my仅迁移。我删除了所有内容,然后又重新迁移了
import ckeditor_uploader.fields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('slug', models.SlugField(max_length=150)),
],
options={
'verbose_name': 'catergory',
'verbose_name_plural': 'catergories',
'ordering': ('name',),
},
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('slug', models.SlugField(default='', help_text='A short label, generally used in URLs.', max_length=100)),
('image', models.ImageField(default='default.jpg', upload_to='profile_pics')),
('content', ckeditor_uploader.fields.RichTextUploadingField(blank=True, null=True)),
('date_posted', models.DateTimeField(default=django.utils.timezone.now)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.Category')),
],
options={
'ordering': ['-date_posted'],
},
),
]
模板文件-blog_view
{% extends "blog/base.html" %}
{% block content %}
<main class="mt-5 pt-5">
<div class="container">
<section class="card wow fadeIn" style="background-image: url(https://mdbootstrap.com/img/Photos/Others/gradient1.jpg);">
<!-- Content -->
<div class="card-body text-white text-center py-5 px-5 my-5">
<h1 class="mb-4">
<strong>Učite kuvanje sa mnom</strong>
</h1>
<h2 class="big-headline">
<strong>BLOG</strong>
</h2>
<p class="mb-4">
<strong>Najbolji i besplatni saveti kako da od običnog kuvara postanete sef kuhinje</strong>
</p>
<a target="_blank" href="#" class="btn btn-outline-white btn-lg">Kontaktirajte me
<i class="fas fa-utensils ml-2"></i>
</a>
</div>
</section>
<!-- posts -->
<section>
<h2 class="h1-responsive font-weight-bold text-center pt-5" style="color: #333;">Naši Postovi</h2>
<hr class="mb-5 line-split">
<p class="text-center dark-grey-text w-responsive mx-auto p-2">Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
{% for post in posts %}
<div class="row pt-5">
<div class="col-lg-5 col-xl-4">
<div class="view overlay rounded z-depth-1-half mb-lg-0 mb-4">
<img class="img-fluid" src="{{ post.image.url }}" alt="Sample image">
<a>
<div class="mask rgba-white-slight"></div>
</a>
</div>
</div>
<div class="col-lg-7 col-xl-8">
<h3 class="font-weight-bold mb-3"><strong>{{ post.title }}</strong></h3>
<p class="dark-grey-text">{{ post.content|truncatechars:255}}</p>
<p>by <a class="font-weight-bold">{{ post.author }}</a>, {{ post.date_posted|date:"F d, Y" }}</p>
<a href="{{ post.get_absolute_url }}" class="btn btn-primary btn-md">Read more</a>
</div>
</div>
<hr class="my-5">
{% endfor %}
</section>
<!-- Section: Blog v.3 -->
</div>
</main>
<div class="container text-center">
<div class="pagination">
<span class="step-links">
{% if posts.has_previous %}
<a href="?page=1">« 1 - </a>
<a href="?page={{ posts.previous_page_number }}">predhodna</a>
{% endif %}
<span class="current">
Stranica {{ posts.title }} broj {{ posts.paginator.num_pages }}.
</span>
{% if posts.has_next %}
<a href="?page={{ posts.next_page_number }}">next</a>
<a href="?page={{ posts.paginator.num_pages }}">last »</a>
{% endif %}
</span>
</div>
</div>
{% endblock content %}
urls.py
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
from .views import PostDetailView
urlpatterns = [
path('', views.index_view, name='index-page'),
path('blog/', views.blog_view, name='blog-page'),
path('blog/<slug:slug>', views.PostDetailView.as_view(), name='detail'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.py
from django.shortcuts import render, redirect
from django.core.paginator import Paginator
from django.contrib import messages
from . models import Post
from django.core.mail import send_mail
from django.views.generic import DetailView, ListView
def index_view(request):
return render(request, 'blog/index_view.html')
def blog_view(request):
posts = Post.objects.all()
paginator = Paginator(posts, 5)
page = request.GET.get('page')
posts = paginator.get_page(page)
context = {
'posts': Post.objects.all()
}
return render(request, 'blog/blog_view.html', {'posts': posts})
class PostDetailView(DetailView):
model = Post
template_name = 'blog/detail.html'
context_object_name = 'post'
BASE.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.10.0/baguetteBox.min.css" />
<link href="https://fonts.googleapis.com/css?family=Lora" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Courgette|EB+Garamond|Prompt" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.16/css/mdb.min.css" rel="stylesheet">
<link rel="stylesheet" href="text/css" href="{% static 'blog/animate.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">>
{% if title %}
<title>Pocetna- {{ title }}</title>
{% else %}
<title>Pocetna</title>
{% endif %}
</head>
<body>
<header class="site-header">
<nav class="navbar navbar-expand-md navbar-light bg-steel fixed-top">
<div class="w-75 container-fluid">
<a class="logo nav-link" href="{% url 'index-page' %}">Tri Musketara</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
<div class="navbar-nav mr-auto">
</div>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link nav-page" style="color:#f3f3f3;" href="{% url 'index-page' %}">Početna</a>
</li>
<li class="nav-item">
<a class="nav-link nav-page" style="color:#f3f3f3;" href="{% url 'about-page' %}">O Nama</a>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#f3f3f3;" href="{% url 'blog-page' %}">Blog</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" style="color:#f3f3f3;" href="#" id="#navbarDropdown" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Usluge
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Postavka kuhinje</a>
<a class="dropdown-item" href="#">Kuvanje na Vašoj adresi</a>
<a class="dropdown-item" href="{% url 'recipes-page' %}">Recepti</a>
<a class="dropdown-item" href="#">Ketering</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#f3f3f3;" href="{% url 'contact-page' %}">Kontakt</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container-fluid"></div>
{% block content %}{% endblock content %}
</div>
<footer class="container-fluid pt-4 footer pt-5">
<div class="container text-center text-md-left">
<div class="row">
<div class="col-md-6 mt-md-0 mt-3">
<div class="logo pt-5">aa</div>
<h5 class="text-uppercase pt-5">Footer Content</h5>
<p>Here you can use rows and columns here to organize your footer content.</p>
</div>
<hr class="clearfix w-100 d-md-none pb-3">
<div class="col-md-3 mb-md-0 mb-3">
<h5 class="text-uppercase pt-5">Links</h5>
<ul class="list-unstyled pt-5">
<li>
<a href="#!"><i class="fa fa-twitter"></i></a>
</li>
<li>
<a href="#!"><i class="fa fa-facebook"></i></a>
</li>
<li>
<a href="#!"><i class="fa fa-instagram"></i></a>
</li>
<li>
<a href="#!"><i class="fa fa-youtube"></i></a>
</li>
</ul>
</div>
<div class="col-md-3 mb-md-0 mb-3">
<h5 class="text-uppercase pt-5">Links</h5>
<ul class="list-unstyled pt-5">
<li>
<a href="{% url 'contact-page' %}">Kontakt</a>
</li>
<li>
<a href="#!">Recepti</a>
</li>
<li>
<a href="#!">Blog</a>
</li>
<li>
<a href="#!">O nama</a>
</li>
</ul>
</div>
</div>
</div>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.10.0/baguetteBox.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script>
baguetteBox.run('.compact-gallery', { animation: 'slideIn' });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.16/js/mdb.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.js"></script>
<script> new WOW().init(); </script>
<script>
$(document).ready(function () {
$('.customer-logos').slick({
slidesToShow: 5,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 3000,
arrows: false,
dots: false,
pauseOnHover: false,
responsive: [{
breakpoint: 768,
settings: {
slidesToShow: 4
}
}, {
breakpoint: 520,
settings: {
slidesToShow: 2
}
}]
});
});
</script>
</body>
</html>
答案 0 :(得分:1)
在以下几行进行更改:
替换
verbose_name = 'catergory'
verbose_name_plural = 'catergories'
到
verbose_name = 'category'
verbose_name_plural = 'categories'