Aldrich Heinz Alvarez
Aldrich Heinz Alvarez

Reputation: 11

OperationalError at /admin/app/review/ no such column: app_review.startup_id

I keep getting this error whenever I open my Django admin page and click these models.

Here is my models.py

from django.db import models
from django.utils import timezone
from django.utils.crypto import get_random_string
import string
import random

code = get_random_string()

class Startup(models.Model):
   code = models.CharField(max_length=12, default=code, unique=True)
   name = models.CharField(max_length=30)
   lead = models.CharField(max_length=50, unique=True)
   problem = models.CharField(max_length=100)
   solution = models.CharField(max_length=100)
   date = models.DateTimeField(default=timezone.now)

   def __str__(self):
      return self.name

class Idea(models.Model):
   startup = models.ForeignKey(Startup, on_delete=models.CASCADE)
   summary = models.CharField(max_length=100)
   attachment = models.FileField(upload_to='attachments/idea')
   member = models.CharField(max_length=50, unique=True)
   date = models.DateTimeField(default=timezone.now)
   
   DRAFT = 'DRAFT'
   REVISED = 'REVISED'
   FINAL = 'FINAL'
   TYPE_CHOICES = [
      (DRAFT, 'Draft'),
      (REVISED, 'Revised'),
      (FINAL, 'Final'),
   ]

   type = models.CharField(max_length=7, choices=TYPE_CHOICES, default=DRAFT)
   
   def __str__(self):
      return self.summary

class Comment(models.Model):
   startup = models.ForeignKey(Startup, on_delete=models.CASCADE)
   idea = models.ForeignKey(Idea, on_delete=models.CASCADE)
   comment = models.CharField(max_length=100)
   member = models.CharField(max_length=50, unique=True)
   date = models.DateTimeField(default=timezone.now)

   GOOD = 'GOOD'
   FINE = 'FINE'
   BAD = 'BAD'
   RATING_CHOICES = [
      (GOOD, 'Good'),
      (FINE, 'Fine'),
      (BAD, 'Bad'),
   ]

   rating = models.CharField(max_length=4, choices=RATING_CHOICES, default=GOOD)
   
   def __str__(self):
      return self.comment

class Product(models.Model):
   startup = models.ForeignKey(Startup, on_delete=models.CASCADE)
   attachment = models.FileField(upload_to='attachment/product')
   version = models.IntegerField()
   changes = models.CharField(max_length=100)
   member = models.CharField(max_length=50, unique=True)
   date = models.DateTimeField(default=timezone.now)

   
   INITIAL = 'INITIAL'
   IMPROVE = 'IMPROVE'
   FINISHED = 'FINISHED'
   STAGE_CHOICES = [
      (INITIAL, 'Initial'),
      (IMPROVE, 'Improve'),
      (FINISHED, 'Finished'),
   ]

   stage = models.CharField(max_length=9, choices=STAGE_CHOICES, default=INITIAL)

   def __str__(self):
      return self.changes

class Review(models.Model):
   startup = models.ForeignKey(Startup, on_delete=models.CASCADE)
   product = models.ForeignKey(Product, on_delete=models.CASCADE)
   review = models.CharField(max_length=100)
   member = models.CharField(max_length=50, unique=True)
   date = models.DateTimeField(default=timezone.now)

   GOOD = 'GOOD'
   FINE = 'FINE'
   BAD = 'BAD'
   RATING_CHOICES = [
      (GOOD, 'Good'),
      (FINE, 'Fine'),
      (BAD, 'Bad'),
   ]

   rating = models.CharField(max_length=4, choices=RATING_CHOICES, default=GOOD)
   
   def __str__(self):
      return self.review

Upvotes: 1

Views: 1072

Answers (3)

Ersain
Ersain

Reputation: 1520

Whenever you make changes in your models, run:

$ python manage.py makemigrations

$ python manage.py migrate

to apply the changes in the DB.

Migrations | Django documentation

Upvotes: 1

ladhari
ladhari

Reputation: 535

Did you run migrations when you added these models?

./manage.py makemigrations
./manage.py migrate

and did you add "app" to INSTALLED_APPS

Upvotes: 1

SANGEETH SUBRAMONIAM
SANGEETH SUBRAMONIAM

Reputation: 1074

You might have made changes to the model and migrated again which would have caused problems in existing instances of the model or newly created model. So in your migrations.py folder delete the latest migrations and try remigrating

check this similar solution :

operational errors: no such column solution

Upvotes: 0

Related Questions