문제

I'm setting up a new server in AWS (Ubuntu) to run Django, using WSGI, Python 2.7, Apache2 and MySQL. The initial page and the admin page are showing fine but I'm not able to login to the admin page after running syndcb. I have checked my database and the tables were built successfully, but when I try to login to the /admin/ page, I get:

OperationalError at /admin/ unable to open database file

/usr/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py in get_new_connection, line 346

I'm suspecting that is a cache somewhere pointing to sqlite3, which is wrong. There are no .pyc files in my app folder and here is the relevant part of my settings.py:

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'name',
        'USER': 'user',
        'PASSWORD': 'pw',
        'HOST': 'myhost',
        'PORT': '3306',
    }
}

Restarting Apache also won't work.

UPDATE Traceback:

Environment:


Request Method: POST
Request URL: http://url/admin/

Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in wrapper
  215.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  197.                 return self.login(request)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in login
  330.         return login(request, **defaults)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  75.             return view(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/views.py" in login
  36.         if form.is_valid():
File "/usr/lib/python2.7/dist-packages/django/forms/forms.py" in is_valid
  129.         return self.is_bound and not bool(self.errors)
File "/usr/lib/python2.7/dist-packages/django/forms/forms.py" in errors
  121.             self.full_clean()
File "/usr/lib/python2.7/dist-packages/django/forms/forms.py" in full_clean
  274.         self._clean_form()
File "/usr/lib/python2.7/dist-packages/django/forms/forms.py" in _clean_form
  300.             self.cleaned_data = self.clean()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/forms.py" in clean
  28.             self.user_cache = authenticate(username=username, password=password)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/__init__.py" in authenticate
  49.             user = backend.authenticate(**credentials)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in authenticate
  16.             user = UserModel._default_manager.get_by_natural_key(username)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/models.py" in get_by_natural_key
  167.         return self.get(**{self.model.USERNAME_FIELD: username})
File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py" in get
  151.         return self.get_queryset().get(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in get
  301.         num = len(clone)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in __len__
  77.         self._fetch_all()
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
  854.             self._result_cache = list(self.iterator())
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in iterator
  220.         for row in compiler.results_iter():
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in results_iter
  710.         for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  780.         cursor = self.connection.cursor()
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in cursor
  157.             cursor = self.make_debug_cursor(self._cursor())
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in _cursor
  129.         self.ensure_connection()
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in ensure_connection
  124.                 self.connect()
File "/usr/lib/python2.7/dist-packages/django/db/utils.py" in __exit__
  99.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in ensure_connection
  124.                 self.connect()
File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py" in connect
  112.         self.connection = self.get_new_connection(conn_params)
File "/usr/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py" in get_new_connection
  346.         conn = Database.connect(**conn_params)

Exception Type: OperationalError at /admin/
Exception Value: unable to open database file
도움이 되었습니까?

해결책

I vet that 'myhost' is not in your resolvconf file, so I'll put 127.0.0.1 or the ip you need to connect to your DB

If that's correct the next thing to look at, will be the apache config and BBDD permisions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top