How can I get an old Django project back and running like it was before?

1.1k views Asked by At

I have an old Django project that I haven't kept up, and now I'd like to make necessary changes to work with current versions of Django and related software. I'm not sure what to make of the current error; it appears to me that it doesn't have something under the django.core umbrella, but my Django 1.9.2 installation is up to date:

[2016-02-14 17:23:10 +0000] [4605] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 141, in load
    mod = util.import_module("gunicorn.app.django_wsgi")
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/django_wsgi.py", line 21, in 
    from django.core.management.validation import get_validation_errors
ImportError: No module named validation
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 141, in load
    mod = util.import_module("gunicorn.app.django_wsgi")
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/django_wsgi.py", line 21, in 
    from django.core.management.validation import get_validation_errors
ImportError: No module named validation
[2016-02-14 17:23:10 +0000] [4605] [INFO] Worker exiting (pid: 4605)
[2016-02-14 17:23:11 +0000] [4597] [INFO] Shutting down: Master
[2016-02-14 17:23:11 +0000] [4597] [INFO] Reason: Worker failed to boot.
root@localhost:~/unixytalk# pip install Django==1.9.2
Requirement already satisfied (use --upgrade to upgrade): Django==1.9.2 in /usr/local/lib/python2.7/dist-packages

How can I port my project to newer Django? How, for instance, can I provide (or tell that it is provided) django.core.management.validation?

And if I may include another archaic question, what takes the place of a "python manage.py syncdb" to initialize a database to a project an application can take care of?

--UPDATE--

There was something I was walking away from this note thinking...

I posted about a screenful of output in which Gunicorn was failing to work appropriately, through an import from django.core.management.validation that was placed there apparently by Gunicorn's process, and not in any sense an initiative on my part to directly interact with that module. (As I had stated, I was trying to get an older system to work with newer code. At least for this project, that does not in any sense include initiative to use django.core.management.validation.)

Not to put too fine a point on it, but the person responding related to my screenful of pasted output as TL;DR.

That's not me who has set the pace for TL;DR; it's the person helping me.

By a copy-and-paste metric in terms of rendered characters on a "select all and copy," TL;DR is 2412 characters.

The hefty release notes, then, being 53714 characters, qualifies as TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR TL;DR in its last installment alone, reminiscent of both Jakob Nielsen's article on why user education is not the answer to security issues, and the Nix packaging system which is meant to let everything keep its own needed versions of its package system instead of making everything fit a single Procrustean bed of whatever is the currently installed version.

This is kind of deviating from my original question, except that it's not. My original question was intended as, "How can I give a slight sprinkling of pixel dust and reanimate a fairly simple older Django project?" Now things look more like "The fact that I can no longer run what I left as a working project is the tip of the iceberg. Given that I'm a decent Django developer but not a super-focused Django specialist, and I work with many technologies, bitrot looks like a source of a lot of pain."

Ok; enough complaining, although I suspect there's a Programmers post to be found in this.

1

There are 1 answers

6
grantmcconnaughey On

1) To port to newer versions of Django, I would read every set of release notes from the version you started with to the version you're going to. Definitely read the release notes for Django 1.9, taking special care to read about the deprecated, backwards incompatible, and removed features near the bottom.

2) To check if django.core.management.validation is provided you can do a try/except around your import:

try:
    from django.core.management.validation import get_validation_errors
    validation_errors_imported = True
except ImportError:
    get_validation_errors = None
    validation_errors_imported = False

3) Lastly, you will no longer run python manage.py syncdb. As of Django 1.7 it is python manage.py migrate. Good luck!