【问题标题】:Django Oscar "ProgrammingError at /admin/" MySQL tableDjango Oscar "ProgrammingError at /admin/" MySQL 表
【发布时间】:2014-10-25 19:24:30
【问题描述】:

尝试制作我的第二个 Django 应用:基于 Django Oscar 的商店。我正在关注关于 RTFD 的教程。我对这个阶段有问题http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html#creating-product-classes-and-fulfillment-partners

每个 Oscar 部署都需要至少一个产品类别和一个 履行合作伙伴。这些不是自动创建的 高度特定于您要建立的商店。最快的设置方法 他们是在登录 Django 管理界面 localhost:8000/admin/ 并在那里创建两者的实例。为一个 部署设置,我们建议将它们创建为数据迁移。

但是,当我尝试登录管理员时,生成的错误是:

ProgrammingError at /admin/

(1146, "Table 'winestoreoscar.django_admin_log' doesn't exist")
....
Error during template rendering

In template /home/david/.virtualenvs/winestoreoscar/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/index.html, error at line 65
1146

此模板显示在错误中,此行突出显示:

 <ul class="actionlist">
**65    {% for entry in admin_log %}**
66  <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">

所以看起来我缺少一张桌子。我使用 MySQL 作为数据库。在 mysql 提示符下,我尝试了明显的..

mysql> CREATE TABLE winestoreoscar.django_admin_log;

但收到错误消息...

ERROR 1113 (42000): A table must have at least 1 column

然后我尝试删除管理模板中的整个 for 循环,并且管理成功呈现,但尝试保存导致上一个错误。

现在我被困住了。非常感谢任何帮助。

编辑: 这是来自基本目录的树(想 - 我需要一个 admin.py.. 吗?):

├── manage.py
└── oscarwinestore
    ├── __init__.py
    ├── __init__.pyc
    ├── settings.py
    ├── settings.py~
    ├── settings.pyc
    ├── urls.py
    ├── urls.py~
    ├── urls.pyc
    ├── wsgi.py
    └── wsgi.pyc

我的 urls.py 是

from django.conf.urls import include, url
from oscar.app import application
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    url(r'^i18n/', include('django.conf.urls.i18n')),

    # The Django admin is not officially supported; expect breakage.
    # Nonetheless, it's often useful for debugging.
    url(r'^admin/', include(admin.site.urls)),

    url(r'', include(application.urls)),
]

【问题讨论】:

    标签: mysql django django-oscar


    【解决方案1】:

    您需要使用syncdbmigrate 创建表,按照the docs

    $ python manage.py syncdb --noinput
    $ python manage.py migrate
    

    你做到了吗?

    【讨论】:

    • 这应该是评论,而不是答案。
    • 哦。即使它可能是评论..!那是对的。我之前确实运行过syn​​cdb并进行了迁移。然后我将 from django.contrib import admin 和 admin.autodiscover() 添加到 urls.py,因为它们(出于某种奇怪的原因)在构建中丢失了。再次运行同步/迁移修复它。你们是最棒的。问题解决了。
    • 嗯?正如错误所证明的那样,他没有创建表。我建议他使用syncdbmigrate 创建表格。你希望我如何回答这个问题?
    • 是的,抱歉,请编辑问题,为您投票。 @DominicRodger
    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 2019-07-14
    • 2023-03-14
    • 2017-04-19
    • 2023-03-26
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多