dimanche 26 mars 2017

New Form Model Not Working - Exception Value: no such table

I've created a comment form for my blog site and I'm having trouble getting the form to work correctly. I can post comments for each blog post from the admin pages, but when I try to submit the form to post a comment I'm getting a table does not exists error.

I've researched many questions with people getting the same errors, but non seem to directly relate to the issue I'm having. I've run ./manage.py makemigrates && ./manage.py migrate and it's showing I have no pending migrations. Any help would be greatly appreciated.

Here's my relevant code:

blog/models.py

class BlogPage(Page):
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)
    #tag manager
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True)

    #get feature image
    def main_image(self):
        gallery_item = self.gallery_images.first()
        if gallery_item:
            return gallery_item.image
        else:
            return None


    def serve(self, request):
        from .forms import CommentForm

        if request.method == 'POST':
            form = CommentForm(request.POST)

            if form.is_valid():
                comment = form.save(commit=False)
                comment.page_id = self.id
                comment.save()
                return redirect(self.url)
        else:
            form = CommentForm()

        return render(request, self.template, {
            'page': self,
            'form': form,
        })

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('date'),
            FieldPanel('tags'),
        ], heading="Blog information"),
        FieldPanel('intro'),
        FieldPanel('body'),
        InlinePanel('gallery_images', label="Gallery images"),
        InlinePanel('comments', label='Comments'),
    ]


class BlogPageComment(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    comment_author = models.CharField(max_length=50)
    text = models.TextField()
    created_date = models.DateTimeField(default=timezone.now)
    approved_comment = models.BooleanField(default=False)

    class Meta:
        abstract = True


class BlogPageComments(Orderable, BlogPageComment):
    page = ParentalKey('BlogPage', related_name='comments')

blog/forms.py

from django import forms
from .models import BlogPageComment

class CommentForm(forms.ModelForm):

    class Meta:
        model = BlogPageComment
        fields = ('comment_author', 'text',)

Errors:

Environment:

Request Method: POST
Request URL: http://ift.tt/2nl6dbg

Django Version: 1.10.6
Python Version: 2.7.12
Installed Applications:
[u'home',
 u'search',
 u'wagtail.wagtailforms',
 u'wagtail.wagtailredirects',
 u'wagtail.wagtailembeds',
 u'wagtail.wagtailsites',
 u'wagtail.wagtailusers',
 u'wagtail.wagtailsnippets',
 u'wagtail.wagtaildocs',
 u'wagtail.wagtailimages',
 u'wagtail.wagtailsearch',
 u'wagtail.wagtailadmin',
 u'wagtail.wagtailcore',
 u'wagtail.contrib.modeladmin',
 u'modelcluster',
 u'taggit',
 u'django.contrib.admin',
 u'django.contrib.auth',
 u'django.contrib.contenttypes',
 u'django.contrib.sessions',
 u'django.contrib.messages',
 u'django.contrib.staticfiles',
 u'blog']
Installed Middleware:
[u'django.contrib.sessions.middleware.SessionMiddleware',
 u'django.middleware.common.CommonMiddleware',
 u'django.middleware.csrf.CsrfViewMiddleware',
 u'django.contrib.auth.middleware.AuthenticationMiddleware',
 u'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 u'django.contrib.messages.middleware.MessageMiddleware',
 u'django.middleware.clickjacking.XFrameOptionsMiddleware',
 u'django.middleware.security.SecurityMiddleware',
 u'wagtail.wagtailcore.middleware.SiteMiddleware',
 u'wagtail.wagtailredirects.middleware.RedirectMiddleware']



Traceback:

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  42.             response = get_response(request)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/wagtail/wagtailcore/views.py" in serve
  27.     return page.serve(request, *args, **kwargs)

File "/home/kenneth/development/web/sites/mysite/dynamicsalesops/blog/models.py" in serve
  69.               comment.save()

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/base.py" in save
  796.                        force_update=force_update, update_fields=update_fields)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  824.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/base.py" in _save_table
  889.                                       forced_update)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/base.py" in _do_update
  939.         return filtered._update(values) > 0

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/query.py" in _update
  654.         return query.get_compiler(self.db).execute_sql(CURSOR)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1148.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  835.             cursor.execute(sql, params)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  64.                 return self.cursor.execute(sql, params)

File "/home/kenneth/development/web/sites/mysite/wagtailenv/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
  337.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /blog/my-blog-post/
Exception Value: no such table: blog_blogpagecomment




Aucun commentaire:

Enregistrer un commentaire