Forums

Django makemigrations not working after upgrade from python2.7 to 3.5

I recently upgraded my app from python2.7 to 3.5 and to the latest version of Django. Now django makemigrations doesn't seem to do anything. python3.5 manage.py makemigrations kbfb --verbosity 3 gives no output, and doesn't seem to take any action, even though I have made several changes to the models.py file. It doesn't pick up these differences as it used to. I followed the instructions for https://help.pythonanywhere.com/pages/VirtualEnvForNewerDjango/ and created a new virtual env. I also changed the python version to 3.5 in the web configuration page. The app loads and runs fine, but I just can't seem to trigger new migrations. Any guidance would be much appreciated.

PS: There is no record in any of the logs to indicate that makemigrations has run or had any errors.

Interesting. Does manage.py work at all? For example, do you get a Python shell if you run python3.5 manage.py shell?

No shell appears when I do that. I changed the first line in manage.py below to use 3.5 rather than 2.7. Any other changes needed?:

#!/usr/bin/env python3.5
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bushfire.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

[edit by admin: formatting]

That's really weird -- the code looks OK to me. Is it printing out anything at all when you run it? Or just returning you to the bash prompt? If it's not printing out anything, maybe put a couple of print statements in there to find out what it's doing?

manage.py is not outputting anything sensible, no matter what I try. name = "main" and sys.argv = ['manage.py', 'makemigrations', 'kbfb', '--verbosity', '3'] as expected.

I even tried rebuilding the app from scratch, with a new virtualenv, and still have the same problem. manage.py can't even run a python shell inside the venv.

I did try to use the original mysql database in the rebuilt app to save rebuilding the db, but it looks like I'll need to start again and rebuild that as well, as something is completely broken here.

When I do 'set' at the virtualenv prompt, it looks fine at first, but then seems to be corrupted:

(django2) 05:59 ~/projects/shadmin/kbfb $ set BASH=/bin/bash BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:interactive_comments:progcomp:promptvars:sourcepath BASH_ALIASES=() BASH_ARGC=() BASH_ARGV=() BASH_CMDS=() BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]="4" [1]="3" [2]="11" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu") BASH_VERSION='4.3.11(1)-release' COLUMNS=167 DIRSTACK=() EUID=3529987 GREEN='[\033[0;32m]' GROUPS=() HISTCONTROL=ignoreboth HISTFILE=/home/ibowditch/.bash_history HISTFILESIZE=500 HISTSIZE=500 HOME=/home/ibowditch HOSTNAME=conrad-liveconsole2 HOST ... USERNAME=ibowditch VIRTUALENVWRAPPER_ENV_BIN_DIR=bin VIRTUALENVWRAPPER_HOOK_DIR=/home/ibowditch/.virtualenvs VIRTUALENVWRAPPER_PROJECT_FILENAME=.project VIRTUALENVWRAPPER_PYTHON=/usr/bin/python VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh VIRTUALENVWRAPPER_VIRTUALENV=virtualenv VIRTUALENVWRAPPER_VIRTUALENV_CLONE=virtualenv-clone VIRTUALENVWRAPPER_WORKON_CD=1 VIRTUAL_ENV=/home/ibowditch/.virtualenvs/django2 WORKON_HOME=/home/ibowditch/.virtualenvs YELLOW='[\033[0;33m]' =/tmp/tmprc.10086765 _OLD_VIRTUAL_PATH=/home/ibowditch/.local/bin:/home/ibowditch/.local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin _OLD_VIRTUAL_PS1='[\033[0;37m]$(date +%H:%M) \w[\033[0;33m] $(parse_git_branch)[\033[1;32m]$ [\033[0;37m]' __git_printf_supports_v=yes _backup_glob='@(##|@(~|.@(bak|orig|rej|swp|dpkg|rpm@(orig|new|save))))' _xspecs=([freeamp]="!.@(mp3|og[ag]|pls|m3u)" [cdiff]="!.@(dif?(f)|?(d)patch)?(.@([gx]z|bz2|lzma))" [bibtex]="!.aux" [rgview]=".@(o|so|so.!(conf|/)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [oowriter]="!.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm)" [chromium-browser]="!.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [tex]="!.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [zathura]="!.@(cb[rz7t]|djv?(u)|?(e)ps|pdf)" [netscape]="!.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [acroread]="!.[pf]df" [makeinfo]="!.texi" [kwrite]=".@(o|so|so.!(conf|/)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [gview]=".@(o|so|so.!(conf|/)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [qiv]="!.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|svg)" [lrunzip]="!.lrz" [bzcat]="!.?(t)bz?(2)" [a .... info]="!.@(zip|[ejsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|do[ct][xm]|p[op]t[mx]|xl[st][xm])" [epiphany]="!.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [gunzip]="!.@(Z|[gGd]z|t[ag]z)" [google-chrome]="!.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [okular]="!.@(okular|@(?(e|x)ps|?(E|X)PS|[pf]df|[PF]DF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|epub|EPUB|odt|ODT|fb?(2)|FB?(2)|mobi|MOBI|g3|G3|chm|CHM)?(.?(gz|GZ|bz2|BZ2)))" [slitex]="!.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [galeon]="!.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [bzme]="!.@(zip|z|gz|tgz)" [xfig]="!.fig" [xzcat]="!.@(?(t)xz|tlz|lzma)" [timidity]="!.@(mid?(i)|rmi|rcp|[gr]36|g18|mod|xm|it|x3m|s[3t]m|kar)" [dviselect]="!.dvi" [xdvi]="!*.@(dvi|DVI)?(.@(gz|Z|bz2))" ) a=django2 activate=/home/ibowditch/.virtualenvs/django2/bin/activate i=1 taskcommand=task tst=-lt virtualenvwrapper_original_deactivate=$'virtualenv_deactivate () \n{ \n unset -f pydoc > /dev/null 2>&1;\n if ! [ -z "${_OLD_VIRTUAL_PATH+}" ]; then\n PATH="$OLD_VIRTUAL_PATH";\n export PATH;\n unset _OLD_VIRTUAL_PATH;\n fi;\n if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+}" ]; then\n PYTHONHOME="$OLD_VIRTUAL_PYTHONHOME";\n export PYTHONHOME;\n unset _OLD_VIRTUAL_PYTHONHOME;\n fi;\n if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ]; then\n hash -r 2> /dev/null;\n fi;\n if ! [ -z "${_OLD_VIRTUAL_PS1+}" ]; then\n PS1="$_OLD_VIRTUAL_PS1";\n export PS1;\n unset _OLD_VIRTUAL_PS1;\n fi;\n unset VIRTUAL_ENV;\n if [ ! "${1-}" = "nondestructive" ]; then\n unset -f virtualenv_deactivate;\n fi\n}' _R () { local cur loneOpts helpOpts stdOpts argOpts versOpts cmds cmd furtherOpts; local fileNames dirNames i lastToken; COMPREPLY=(); cur=${COMP_WORDS[COMP_CWORD]}; loneOpts='--version RHOME'; versOpts='-v --version'; helpOpts='-h --help'; stdOpts='--save --no-save --no-environ --no-site-file \ --no-init-file --restore --no-restore-data --no-restore-history \ --no-restore --vanilla --no-readline -q --quiet --silent --slave \ --interactive --verbose -d -g --args -f -e'; argOpts='--min-vsize --max-vsize --min-nsize --max-nsize \ --encoding --max-ppsize --debugger --debugger-args \ --gui --arch --file'; cmds='BATCH COMPILE SHLIB INSTALL REMOVE build check LINK Rprof \ Rdconv Rd2pdf Rd2txt Stangle Sweave Rdiff config javareconf rtags'; fileNames='';

PS: to be clear, manage.py is not outputting anything, and just returns to the command prompt after a short delay. I added some tracing to manage.py and it seems to be working as expected, except the called command does nothing.

PPS: I just tried to create another virtualenv using instructions from https://help.pythonanywhere.com/pages/FollowingTheDjangoTutorial/, ie. $ mkvirtualenv django4 --python=/usr/bin/python3.6 The resulting environment (when I type 'set' at the command prompt) is a similar mess to what I reported earlier.

  1. i don't think you can just randomly change the Python version and Django version for a Django project. Your best bet is to start a new Django project with the correct Python version and Django version and then port you code into it.
  2. I can't see anything in the unformatted env. What exactly makes you say it's "corrupted"?

I finally tracked this down to an error in my settings.py. Sorry for the bother, and thanks for your help.

On the environment (as shown by set command inside venv), there is a value called "taskcommand=task" which is an enormous script hundreds of lines long. Is that normal?

Glad you worked it out! It's weird that it didn't give you a more useful error message, though.

The taskcommand=task thing doesn't ring any bells -- certainly I don't seem to have anything like that in any of my virtualenvs.