1

I'm developing a test app in Google App Engine with Django + Python 3.7; I successfully launched the test app and created a new app both at local side and on app engine server. Now I'm trying to create a little bit more complex model. I created the model + view + url file and template and migrated it (with an apparent success), but if I try to visualize the template at the local server, I retrieve this error:

ProgrammingError at / (1146, "Table 'djangoseo.keywords_keywords' doesn't exist")

I tried to migrate the model another time, used syncdb command with no success.

This is the model

from django.db import models


class Keywords(models.Model):
    keyword_name = models.CharField(max_length=200)
    keyword_tags = models.ManyToManyField('Tags')
    keyword_urls = models.ManyToManyField('Urls', through='Rankings')
    avg_volume = models.IntegerField(default=0)
    jan_volume = models.IntegerField(default=0)
    feb_volume = models.IntegerField(default=0)
    mar_volume = models.IntegerField(default=0)
    apr_volume = models.IntegerField(default=0)
    may_volume = models.IntegerField(default=0)
    jun_volume = models.IntegerField(default=0)
    jul_volume = models.IntegerField(default=0)
    aug_volume = models.IntegerField(default=0)
    sep_volume = models.IntegerField(default=0)
    oct_volume = models.IntegerField(default=0)
    nov_volume = models.IntegerField(default=0)
    dec_volume = models.IntegerField(default=0)
    intent = models.CharField(max_length=200)
    micromoment = models.CharField(max_length=200)
    language = models.CharField(max_length=200)
    addedby = models.CharField(max_length=200)

    def __str__(self):
        return self.keyword_name

class Tags(models.Model):
    tag_name = models.CharField(max_length=200)
    addedby = models.CharField(max_length=200)

    def __str__(self):
        return self.tag_name

class Urls(models.Model):
    url_name = models.CharField(max_length=300)
    domain = models.CharField(max_length=200)

    def __str__(self):
        return self.url_name

class Rankings(models.Model):
    keyword = models.ForeignKey(Keywords, on_delete=models.CASCADE)
    url = models.ForeignKey(Urls, on_delete=models.CASCADE)
    date_ranking = models.DateTimeField()
    ranking = models.IntegerField(default=0)

    def __str__(self):
        return self.ranking'''

This is the view

from django.views import generic

from .models import Keywords


class IndexView(generic.ListView):
    template_name = 'keywords/index.html'
    context_object_name = 'keywords_list'

    def get_queryset(self):
        """Return the first ten keywords."""
        return Keywords.objects.order_by('keyword_name')[:10]

And this is the template for index.html

{% if keywords_list %}
<ul>
{% for keyword in keywords_list %}
    <li>{{ keyword.keyword_name }}</li>
{% endfor %}
</ul>
{% else %}
<p>No keywords are available.</p>
{% endif %}

I retrieve this error:

ProgrammingError at / (1146, "Table 'djangoseo.keywords_keywords' doesn't exist") Request Method: GET Request URL: http://localhost:8000/

How can I fix it? Why do I get it?

Paolo
  • 11
  • 4

1 Answers1

0

If you haven't done an initial migration yet, that could be the issue. Follow the linked initial migration docs first to ensure that that has been done.

If you have done an initial migration, you'll need to check to ensure that when you ran

python manage.py makemigrations

you received a migration file in your module's yourmodule/migrations/ directory. If that file does not exist, you need to double-check your syntax for makemigrations and ensure you are running the command from the same directory that your manage.py file is in.

If you have a migration file, you need to run migrate:

python manage.py migrate

to apply it to the database. To ensure that it applied, check your database for a table named djangomigrations and run select * from djangomigrations order by id desc;. If you see your filename in the table, you should be good to go.

tinwhiskers
  • 63
  • 1
  • 1
  • 7