user12137867
user12137867

Reputation:

Operation Error no such column DJANGO pythonanywhere

So i have made change in my model. I added possibility to add picture. It works fine on my computer, but when i try to apply it on internet on pythonanywhere it does not work properly. There even in admin panel i can not add recipe. I have tried delete migrations and migrate again, but it did not help.. Now the website on the intrnet does not work, but on my local server everything is fine.. I do not know how fix it.

My website: http://lui93.pythonanywhere.com/accounts/search/?q=sok

OperationalError at /accounts/search/
no such column: drinks_recipe.recipe_image

OperationalError at /accounts/search/
no such column: drinks_recipe.recipe_image
Request Method: GET
Request URL:    http://lui93.pythonanywhere.com/accounts/search/?q=sok
Django Version: 2.0.13
Exception Type: OperationalError
Exception Value:    
no such column: drinks_recipe.recipe_image
Exception Location: /home/Lui93/.virtualenvs/lui93.pythonanywhere.com/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py in execute, line 305
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.5.6
Python Path:    
['/home/Lui93/lui93.pythonanywhere.com',

Error during template rendering
In template /home/Lui93/lui93.pythonanywhere.com/drinks/templates/drinks/search_results.html, error at line 14

no such column: drinks_recipe.recipe_image

my models:

from django.db import models


class Ingredient(models.Model):

  ingredient_name = models.CharField(max_length=250)

  def __str__(self):
    return self.ingredient_name


class Recipe(models.Model):

  recipe_name = models.CharField(max_length=250)
  preparation = models.CharField(max_length=1000)
  ingredients = models.ManyToManyField(Ingredient)
  recipe_image = models.ImageField(upload_to='images/', default='')


  def __str__(self):
    return self.recipe_name

templates:

<body>
    <div id=container>
      <h1><a href="/">Wróć do strony głównej</a></h1>


    {% if results %}
      {% for drink in results %}
          <p><b>{{ drink.recipe_name }}</b></p>
          <p><u>Preparation:</u> {{ drink.preparation }}</p>
          <p><u>Ingredients:</u>
            {% for ingredient in drink.ingredients.all %}
              {{ingredient.ingredient_name}}{% if not forloop.last %},{% endif %}
            {% endfor %}
          </p>
          <p><img src="{{drink.recipe_image.url}}" alt="{{drink.recipe_name}}"</p>
      {% endfor %}

    {% else %}
      Such ingredients do not exist
    {% endif %}
  </div>
  </body>

Upvotes: 0

Views: 440

Answers (1)

flaab
flaab

Reputation: 581

Django will halt and complain if a model has fields declared, not yet present in the database schema. Either comment the ImageField definition in your model or run python3 manage.py makemigrations and python3 manage.py migrate.

Upvotes: 1

Related Questions