0

I have a problem with my database every time I deploy it to heroku. The code works okay on localhost but shows ProgrammingError when deployed.

When ever I remove the category from the codes, it seems to work but still having another issue with the auth dashboard.

Here is the view.py code

class BlogView(ListView): 
    model = Post 
    template_name = 'blog.html' 
    ordering = ['-post_date'] 
    paginate_by = 10
    
    def get_context_data(self, *args, **kwargs): 
        genres_menu = Category.objects.all()
        context = super(BlogView, self).get_context_data(*args, **kwargs)
        
    
        context["genres_menu"] = genres_menu
        print(context)
        return context

Here is the model.py code

from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from datetime import datetime, date
from ckeditor.fields import RichTextField

    
    class Category(models.Model): 
    name = models.CharField(max_length=255)
    
    def __str__(self):
        return self.name
    
    def get_absolute_url(self):
       return reverse('blog')

class Post(models.Model): 
title = models.CharField(max_length=255) 
author = models.ForeignKey(User, on_delete=models.CASCADE) 
category = models.ForeignKey(Category, on_delete=models.CASCADE) 
thumbnail = models.ImageField(null=True, blank=True, upload_to="thumb_images/blog_post") 
snippet = models.CharField(max_length=255, default='This is a default snippet') 
likes = models.ManyToManyField(User, related_name='blog_posts')



def total_likes(self):
    return self.likes.count()

def \__str_\_(self):
    return self.title + ' | ' + str(self.author)

def get_absolute_url(self):
    return reverse('blog')

Here is the url.py code

from .views import BlogView

urlpatterns = \[
path('blog/', BlogView.as_view(), name='blog'),
\]

Here is the template code

{% if genres_menu %} 
    <div class="widget-area">
    
    <div class="widget-collapse-btn">                    
                        <a class="accordion-toggle" data-bs-toggle="collapse" href="#collapseExample" role="button"
                            aria-expanded="false" aria-controls="collapseExample">
                            <h4 class="widget-collapse-title">Categories</h4>
                        </a>
                    </div>
    
                    <div class="collapse" id="collapseExample">
                        <div class="card card-body none-box">
                            <ul class="category-collapse">
                                {% for item in genres_menu %}
                                <li class="category-collapse-list">
                                    <a href="{% url 'category' item|slugify %}">{{ item }}</a>
                                </li>
    
                                {% endfor %}
    
                            </ul>
                        </div>
                    </div>
    
                </div>
    {% endif %}

I tried clearing the database with - python manage.py flush, makemigration and then migrate once again, but it remained the same.

1 Answers1

0

For this kind of issue even flushing the migrations won't work you just have to drop that table blog_app_post. After you run python manage.py makemigrations app_name after the migration run python manage.py sqlmigrate app_name 0001_initial this will generate all the schema of that particular app then look for the table blog_app_post schema and copy it then create that table manually if your DB is postgres you just connect to DB and paste that schema. NB: This solution is actually good in development mode or local server