django 管理错误 - 无法访问管理页面

django admin error - cannot access admin page

我刚刚开始我的新 django 1.8 项目。我创建了一个超级用户并转到 127.0.0.1:8000/admin/ 并从那里登录。登录后,显示如下错误:

(1054, "Unknown column 'django_content_type.name' in 'field list'")

我搜索了一圈,只发现了一个相关问题,

正如那里的讨论所说,我放弃了我的架构并重新创建了很多次;我仍然得到同样的错误。我数据库中的django_content_typetable只有三个字段:id、app_label和model。它没有已弃用的 'name'。

此外,我可以访问其他网址,如 /admin/auth//admin/auth/users/,但尝试添加更多用户时会出现以下错误(我认为这也是由于与上述相同的问题所致) :

Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

总的来说,我对 Django 还是很陌生。任何帮助将非常感激。谢谢。

这是完整的错误:

OperationalError at /admin/
(1054, "Unknown column 'django_content_type.name' in 'field list'")
    Request Method: GET
    Request URL:    http://127.0.0.1:8000/admin/
    Django Version: 1.7.5
    Exception Type: OperationalError
    Exception Value:    
    (1054, "Unknown column 'django_content_type.name' in 'field list'")
    Exception Location: /usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
    Python Executable:  /usr/bin/python
    Python Version: 2.7.6
    Python Path:    
    ['/home/rahul/Development/rmgl_project',
     '/usr/local/lib/python2.7/dist-packages/virtualenv-12.1.1-py2.7.egg',
     '/usr/lib/python2.7',
     '/usr/lib/python2.7/plat-x86_64-linux-gnu',
     '/usr/lib/python2.7/lib-tk',
     '/usr/lib/python2.7/lib-old',
     '/usr/lib/python2.7/lib-dynload',
     '/usr/local/lib/python2.7/dist-packages',
     '/usr/lib/python2.7/dist-packages',
     '/usr/lib/python2.7/dist-packages/PILcompat',
     '/usr/lib/python2.7/dist-packages/gtk-2.0',
     '/usr/lib/pymodules/python2.7',
     '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
    Server time:    Wed, 8 Jul 2015 07:19:12 +0000

我意识到这个错误显示我的 django 版本为 1.7,而我使用 pip 安装了 django 1.8。我 运行 python manage.py shell 并从那里检查了我的 django 版本(无法 post 截图,rep 不够高)。

$ python manage.py shell
>>> import django
>>> django.VERSION
(1, 8, 2, 'final', 0)
>>>

我该如何纠正这个问题?再次感谢。我正在使用 virtualenv。

编辑:添加 urls.py

"""rmgl_project URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Add an import:  from blog import urls as blog_urls
    2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

添加manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE",     "rmgl_project.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

问题出在 virtualenv - 它没有启用。

为了检查 Django 的版本(以及模块的路径),您可以将以下行添加到 ./manage.py 文件:

print(__import__('django')) # Should print the module information
print(__import__('django').__file__) # Should print the location of __init__.py file

if __name__ == '__main__' 行之后。