将数据库添加到Mezzanine项目会产生" sqlite3.OperationalError:没有这样的表:django_site"

时间:2018-02-14 21:20:45

标签: python django mezzanine django-database

我试图将第三方数据库添加到Mezzanine 4.2.3项目中(根据Student使用Django 1.10.8)。它被称为requirements.txt的应用程序使用。但是,它会产生此错误:food_crud

我读过的大多数解决方案都说sqlite3.OperationalError: no such table: django_sitemakemigrations。有几位说要将migrate添加到django.contrib.sites。我试过了两个。

项目目录布局:

INSTALLED_APPS

180214 food - env_food # virtualenv - food __init__.py settings.py router.py urls.py views.py wsgi.py - food_crud - migrations __init__.py admin.py models.py tests.py views.py - static ... - theme ... __init__.py manage.py movie_data.sql 应用位于food_crudINSTALLED_APPS还包含数据库详细信息:

settings.py

此处DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "db_nate", "USER": "alex", "PASSWORD": "oh no you did not use password did you", "HOST": "localhost", "PORT": "", }, "movies": { "ENGINE": "django.db.backends.sqlite3", "NAME": "movie_data.sql", } } DATABASE_ROUTERS = ['food.router.FoodRouter'] router.py位于同一文件夹中:

settings.py

from food_crud import models class FoodRouter(object): def db_for_read(self, model, **hints): model = models.Movies if model._meta.app_label == 'food_crud': return 'movies' return None

models.py

from django.db import models class Movies(models.Model): id = models.AutoField(primary_key=True) adult = models.TextField() original_language = models.TextField() original_title = models.TextField() title = models.TextField() overview = models.TextField() release_date = models.DateField() genres = models.TextField() production_countries = models.TextField() videos = models.TextField() images = models.TextField() class Meta: app_label = "food_crud" db_table = "movies" managed = False

views.py

from django.views import generic from .models import Movies class MoviesListView(generic.ListView): model = Movies template_name = r'"/food/theme/templates/food_crud/food_crud.html"'

urls.py

回溯:

...
from . import views
from food_crud import views as food_crud_views

urlpatterns += [
    url("^$", views.blog_post_list_index, name="home"),
    url('food/', food_crud_views.MoviesListView.as_view(), name='food_list'),
...

这个相同的项目目录布局及其各种设置(包括数据库)适用于Django 2.0项目。我在这个Mezzanine项目中复制了它们,但是编辑了适合它的名称。我错过了什么?

1 个答案:

答案 0 :(得分:1)

您的路由器硬件将模型编码为电影,这并不奇怪意味着它始终与food_crud应用程序匹配。因此,所有数据库请求都被路由到您的sqlite数据库。

不要这样做;删除覆盖model变量。