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

时间:2015-07-08 07:17:37

标签: python django admin

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

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

我四处搜索,发现了一个相关的问题,here

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

此外,我可以访问其他网址,例如/admin/auth//admin/auth/users/,但尝试添加更多用户会产生以下错误(我认为这也是由于与上述问题相同):< / p>

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版本(无法发布截图,代表不够高)。

$ 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)

1 个答案:

答案 0 :(得分:1)

问题在于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__'行之后。