enewe101 / digidemo

digital democracy engine
1 stars 0 forks source link

Upgrade to Django 1.7 #54

Closed enewe101 closed 9 years ago

enewe101 commented 9 years ago

We've been putting off the upgrade to Django 1.7 (the latest version), because upgrading breaks the app. But now is probably a good time, because we need one of the features introduced in 1.7: migrations.

Migrations are used when changes are made to models, in order to apply those changes to a database that already has data. Migrations tell the database how to to make changes to its structure while preserving the existing data.

Now that we have a live server, and are finding the need to evolve our models, it makes sense to go ahead and migrate.

To make the app work with 1.7, a very small change needs to be made to how the test data fixture is loaded during testing. You'll need to toast your database and rebuild it after upgrading. I'll post instructions in this issue soon. It should be possible for the code base to be compatible with versions 1.6 and 1.7 while we make the shift.

enewe101 commented 9 years ago

Ok, the app is ready for upgrading to Django 1.7. Next time you commit to the branch your working on, checkout master and go do the upgrade instructions below. Afterward you can go back to your branch, merge in master, and continue working using Django 1.7 (as explained below). Here we go:

  1. $ git pull
  2. $ git checkout master
  3. Open up src/digidemo/settings.py and delete or comment the line FIXTURE_DIRS = (os.path.join(PROJECT_DIR, 'data/fixtures'),). That should be around line 114, although our settings files can differ somewhat.
  4. $ sudo pip install Django --upgrade
  5. Wipe your digidemo database by heading into mysql, and doing mysql> drop database digidemo; create database digidemo; then exit mysql
  6. in digidemo/src run $ python manage.py migrate
  7. run the tests to make sure it went well: in digidemo/src run $ python manage.py test

If the tests went well, you can go back to the branch you were working on, merge in master, and continue working, like this:

  1. $ git checkout branch-you-were-working-on
  2. $ git merge master

Post here if you run into problems!

enewe101 commented 9 years ago

live server now running django 1.7.5

mlhuish commented 9 years ago

I ran into a problem with Languages on lines 103 and 104 of my settings.py file and had to remove the _ from before ('English') and ('French') to get my database to sync.

enewe101 commented 9 years ago

@mlhuish -- Ah shoot -- my bad. I forgot to include some of the new settings in the settings.template file. Hmm.. It has always been difficult when making changes to the settings file, because it's not version-controlled, only the settings.py.template file is, and this makes syncing settings.py with settings.py.template a human job, which is error prone.

I think I can make that problem go away. Could you try the following?

  1. commit your work.
  2. Back up your settings file cp settings.py ~settings.py
  3. Pull the latest from the repo. You should get a new branch called local settings
  4. checkout local_settings This will overwrite your settings file (that's why we made a backup). Git might complain when you try to checkout local_settings, because it doesn't want to overwrite your settings file. If so, just delete the file (be sure you made your backup!)
  5. Your new settings file will should need to be changed by you. You'll notice that there's a new file called local_settings.py.template. Copy that in place, removing the .template part. Open it up, and insert your PROJECT_DIR setting and your DATABASES setting. That should be all you need to do.
  6. Run the tests and let me know what happened.

This should greatly simplify things, because all of the machine-specific settings are extracted into a non-version controlled file, while the rest of the settings are version-controlled.

mlhuish commented 9 years ago

Hey @enewe101 Thanks for this! Unfortunately, there were 17 errors and 1 failure after running the test and the site was not loading properly - no static files. However, when testing the site manually on the development server the site loads beautifully and seems to be functioning properly. Do you think there be a problem with my test.py file or is this a settings issue ?

On Mon, Mar 2, 2015 at 3:37 PM, enewe101 notifications@github.com wrote:

@mlhuish https://github.com/mlhuish -- Ah shoot -- my bad. I forgot to include some of the new settings in the settings.template file. Hmm.. It has always been difficult when making changes to the settings file, because it's not version-controlled, only the settings.py.template file is, and this makes syncing settings.py with settings.py.template a human job, which is error prone.

I think I can make that problem go away. Could you try the following?

  1. commit your work.
  2. Back up your settings file cp settings.py ~settings.py
  3. Pull the latest from the repo. You should get a new branch called local settings
  4. checkout local_settings This will overwrite your settings file (that's why we made a backup). Git might complain when you try to checkout local_settings, because it doesn't want to overwrite your settings file. If so, just delete the file (be sure you made your backup!)
  5. Your new settings file will should need to be changed by you. You'll notice that there's a new file called local_settings.py.template. Copy that in place, removing the .template part. Open it up, and insert your PROJECT_DIR setting and your DATABASES setting. That should be all you need to do.
  6. Run the tests and let me know what happened.

This should greatly simplify things, because all of the machine-specific settings are extracted into a non-version controlled file, while the rest of the settings are version-controlled.

— Reply to this email directly or view it on GitHub https://github.com/enewe101/digidemo/issues/54#issuecomment-76813809.

mlhuish commented 9 years ago

also when I try to run python manage.py collectstatic It says the following...

You have requested to collect static files at the destination location as specified in your settings: /home/ange/projects/digidemo/digidemo/src/home/ange/projects/digidemo/digidemo/static

Which is totally not the correct directory. It seems to be merging BASE_DIR with STATIC_ROOT.

enewe101 commented 9 years ago

Hmm. I think there's a settings problem and maybe a fixtures problem too (fixtures contain the test data, and if the test data is different than what's expected, it causes tons of errors).

Let's start with settings. Could you send me your settings.py and local_settings.py -- maybe just email them to me?

enewe101 commented 9 years ago

Sorry about the trouble btw, and thanks for trying all these things!

enewe101 commented 9 years ago

Hey guys, I think everyone is up to speed with Django 1.7 now. I'll close this issue, but if you have trouble you can reopen it.