简体   繁体   中英

django admin error - cannot access admin page

I just started my new django 1.8 project. I created a superuser and went to 127.0.0.1:8000/admin/ and logged in from that. After logging in, it shows the following error:

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

I searched around and found just one relevant question, here .

As said in the discussion there, I dropped my schema and recreated it many times; still I get the same error. The django_content_type table in my database has only three fields: id, app_label and model. It doesn't have 'name' which is deprecated.

Also, I can access other urls like /admin/auth/ , /admin/auth/users/ , but trying to add more users gives the following error(I think this is also coming due to the same problem as above):

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

I'm very new to Django in general. Any help would be much appreciated. Thanks.

Here's the full error:

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

I realised that this error shows my django version as 1.7 whereas I installed django 1.8 using pip . I ran python manage.py shell and checked my django version from there(cannot post screenshot, rep not high enough).

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

How can I correct this? Thanks again. I'm using virtualenv.

Edit: adding 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)),
]

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

The problem was with virtualenv - it was not enabled.

In order to check the version of Django (and the path to the module), you could add the following lines to ./manage.py file:

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

Right after the if __name__ == '__main__' line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM