Django: OperationalError No Such Table

12 浏览
0 Comments

Django: OperationalError No Such Table

我正在构建一个相当简单的应用程序,在我的Django项目中使用Django-CMS。(这是我第一次从头开始尝试一个项目/应用程序。)它的主要目的是存储各种知识产权资产(即由研究人员撰写的文章、书籍等)。

问题是,当我将浏览器指向/research/时,会出现一个错误,提示没有这个表("no such table")。

我正在使用Django 1.6.5和一个sqlite3数据库。

查看python manage.py sql research的结果如下:

BEGIN;

CREATE TABLE "research_researchbase" (

"id" integer NOT NULL PRIMARY KEY,

"pub_date" datetime NOT NULL,

"authors" varchar(200) NOT NULL,

"year" varchar(25) NOT NULL,

"title" varchar(200) NOT NULL,

"subtitle" varchar(200) NOT NULL,

"image_id" integer NOT NULL REFERENCES "filer_image" ("file_ptr_id"),

"link" varchar(200) NOT NULL

)

;

CREATE TABLE "research_journal" (

"researchbase_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "research_researchbase" ("id"),

"journal" varchar(200) NOT NULL,

"abstract" text NOT NULL,

"citation" varchar(200) NOT NULL

)

;

CREATE TABLE "research_encyclopedia_chapter" (

"researchbase_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "research_researchbase" ("id"),

"encyclopedia" varchar(200) NOT NULL,

"publisher" varchar(200) NOT NULL,

"summary" varchar(200) NOT NULL

)

;

CREATE TABLE "research_book" (

"researchbase_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "research_researchbase" ("id"),

"publisher" varchar(200) NOT NULL,

"summary" varchar(200) NOT NULL

)

;

COMMIT;

我已经运行了python manage.py migrate research,并得到以下结果:

/Users/XXX/Documents/repos/sfs/env/lib/python2.7/site-packages/app_data/fields.py:2: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.

from django.utils import simplejson as json

Running migrations for research:

- Nothing to migrate.

- Loading initial data for research.

Installed 0 object(s) from 0 fixture(s)

我已经运行了python manage.py syncdb,并得到以下结果:

Syncing...

Creating tables ...

Installing custom SQL ...

Installing indexes ...

Installed 0 object(s) from 0 fixture(s)

Synced:

> djangocms_admin_style

> django.contrib.auth

> django.contrib.contenttypes

> django.contrib.sessions

> django.contrib.admin

> django.contrib.sites

> django.contrib.sitemaps

> django.contrib.staticfiles

> django.contrib.messages

> mptt

> south

> sekizai

> django_select2

> hvad

Not synced (use migrations):

- djangocms_text_ckeditor

- cms

- menus

- djangocms_style

- djangocms_column

- djangocms_file

- djangocms_flash

- djangocms_googlemap

- djangocms_inherit

- djangocms_link

- djangocms_picture

- djangocms_teaser

- djangocms_video

- reversion

- polls

- djangocms_polls

- aldryn_blog

- easy_thumbnails

- filer

- taggit

- research

(use ./manage.py migrate to migrate these)

这是我的models.py:

from django.db import models

from django.utils import timezone

from filer.fields.image import FilerImageField

import datetime

class ResearchBase(models.Model):

pub_date = models.DateTimeField('date published')

authors = models.CharField(max_length=200)

year = models.CharField(max_length=25)

title = models.CharField(max_length=200)

subtitle = models.CharField(max_length=200, blank=True)

image = FilerImageField()

link = models.CharField(max_length=200, blank=True)

def __unicode__(self):

return self.title

def was_published_recently(self):

return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

class Journal(ResearchBase):

journal = models.CharField(max_length=200)

abstract = models.TextField()

citation = models.CharField(max_length=200)

class Encyclopedia_Chapter(ResearchBase):

encyclopedia = models.CharField(max_length=200)

publisher = models.CharField(max_length=200)

summary = models.CharField(max_length=200)

class Book(ResearchBase):

publisher = models.CharField(max_length=200)

summary = models.CharField(max_length=200)

这是我的views.py(请注意,我通过render传递了两个对象,忽略我尚未包含在整个流程中的Books类的事实):

from django.shortcuts import render, get_object_or_404

from django.http import HttpResponse, Http404

from django.template import RequestContext, loader

from research.models import Journal, Encyclopedia_Chapter, Book

def research_index(request):

latest_journal_list = Journal.objects.order_by('-pub_date')[:5]

latest_chapter_list = Encyclopedia_Chapter.objects.order_by('-pub_date')[:5]

context = {

'latest_journal_list': latest_journal_list,

'latest_chapter_list': latest_chapter_list

}

return render(request, 'research/index.html', context)

def journal_detail(request, journal_id):

journal = get_object_or_404(Journal, pk=journal_id)

return render(request, 'research/journal_detail.html', {'journal': journal})

def chapter_detail(request, chapter_id):

chapter = get_object_or_404(Encyclopedia_Chapter, pk=chapter_id)

return render(request, 'research/chapter_detail.html', {'chapter': chapter})

这是应用程序的url.py:

from django.conf.urls import patterns, url

from research import views

urlpatterns = patterns('',

url(r'^$', views.research_index, name='research'),

url(r'^(?P\d+)/$', views.journal_detail, name='journal_detail'),

url(r'^(?P\d+)/$', views.chapter_detail, name='chapter_detail'),

)

这是index.html模板:

{% extends 'research/base.html' %}

{% block research_content %}

Peer-reviewed Journal Articles

{% if latest_journal_list %}

    {% for journal in latest_journal_list %}

  • {{ journal.journal }}

    {{ journal.title }}

    Read More

  • {% endfor %}

{% else %}

No journals are available.

{% endif %}

Encyclopedia Chapters

{% if latest_chapter_list %}

    {% for chapter in latest_chapter_list %}

  • {{ chapter.journal }}

    {{ chapter.title }}

    Read More

  • {% endfor %}

{% else %}

No encyclopedia chapters are available.

{% endif %}

{% endblock %}

如果有关系的话,这是我的cms_app.py:

from cms.app_base import CMSApp

from cms.apphook_pool import apphook_pool

from django.utils.translation import ugettext_lazy as _

class ResearchApp(CMSApp):

name = _("Research App")

urls = ["research.urls"]

app_name = "research"

apphook_pool.register(ResearchApp)

0