Forums

Unable to use python manage.py migrate

When I am trying to add a user for in my django admin site I get this error:

The above exception (NOT NULL constraint failed: auth_user.last_login) was the direct cause of the following exception: /usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py in get_response

I created the Super user with this command: python manage.py supersuser and was able to login with it. However, adding a user is giving me grief on proceeding with the site.

double check you are using the right version of python when you run migrate/when you are running your webapp.

also are you getting an error when running migrate? or when adding a user on django admin

I am guessing the site by default is using python 3 based on the error. Below is what I ran the error it shows.

$ python manage.py migrate ** Unknown command: 'migrate' ** Type 'manage.py help' for usage.

Our linux system uses python2.7 as the default system python. The webapp you have setup is a python3.5 webapp (you can see this by going to the webapps tab and searching for python version).

To run manage.py migrate, use python3.5

I may have selected to use python 3.5 by accident. I tried using python3 manage.py migrate and it returns the same error as above that its an unrecognized command. I will research why that is happening.

-Thanks

From my research, I was missing south for some reason in my settings.py installed apps. I added it and was able to migrate. Now the site is not running. More research to come but thank you all for helping.

Something went wrong :-( This website is hosted by PythonAnywhere, an online hosting environment. Something went wrong while trying to load it; please try again later. If this is your PythonAnywhere-hosted site, and you just reloaded it, then the problem might simply be that it hasn't loaded up yet. Try refreshing this page and see if this message disappears. If you keep getting this message, you should check your site's server and error logs for any messages — you can view them from the Web tab inside PythonAnywhere. If there's nothing in the logs, and you're sure your site is OK, then it might be a problem on our side. Drop us a line at support@pythonanywhere.com, in the forums, or using the "Send feedback" link on the site, quoting the error code below. Error code: 502-backend

I am close to giving up on the project and may start over. I never had this many issues when building a server and creating the app from within.

There is no South database module 'south.db.sqlite3' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.

So I delete the app and started over again.

Steps: 1. Select to create a new app. 2. Gave it a domain name. 3. Selected Django 1.9 with python 3.5 4. python3 manage.py migrate Unknown command: 'migrate' Type 'manage.py help' for usage. 5. python3 manage.py syncdb You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes 6. User was added 7. Login to the site/admin with the created user and try to add a new user. 8. Exception Value:NOT NULL constraint failed: auth_user.last_login

I think that you're using a version of Django on PythonAnywhere than the code is written for. Make sure that the version of Django you're using on PythonAnywhere is the same as the one that you expect.

Hi Glenn. Can that be the case if I used pythonanywhere's template to build the site? It matches python version with django version?

Django Version: 1.9.3 Python Version: 3.5

I downgraded to python 3.4 and it works. The default template for python 3.5 and django 1.9 does not work.

That's interesting. We'll have to investigate what may be going on there.

Having closely read your posts above, I think the problem you were having was because you were using the command python3 in your bash consoles when you were running the manage.py scripts, instead of using python3.5.

In newly-created PythonAnywhere accounts, python3 starts Python 3.5 (which is probably why my colleagues didn't pick up on this). But in order to avoid breaking backward-compatibility, for older accounts it maps to the most recent version of Python 3 at the time the account was created. For your account, this means it points to Python 3.4.

This explains the weird behaviour you saw. Our current system install of Django for Python 3.4 is 1.6, and for Python 2.7 it's 1.3.7. So the errors you saw Django version mismatch errors, because you'd selected Python 3.5 but were running with one or the older versions.

A couple of follow-on points:

  • When you are using Django management commands, you don't actually need to specify the Python interpreter. If you're in the directory that contains manage.py, then you can just do things like this:

    ./manage.py migrate
    

    This means that you don't need to remember anything about the Python version -- it just works. * You mention south, which doesn't exist in Django 1.9 -- database migrations were integrated into Django in Django 1.7.

Just for completeness -- I created a Django 1.9 app using Python 3.5 in a fresh account, and here are the steps I followed:

  • "Add a new web app"
  • "Django"
  • "Python 3.5 (Django 1.9.3)"
  • Just accepted the defaults on the next page
  • Checked that the basic site (without admin) showed a "Welcome to Django" page.
  • Went to "/admin" on the basic site and confirmed I had a page there.
  • Went to a bash console
  • Ran

    cd mysite
    ./manage.py migrate
    ./manage.py createsuperuser
    
  • Logged in to the admin site.

  • Clicked on the "Add user" link
  • Entered username and password for a user
  • Clicked "Save".

That all worked fine. Because those steps bypass the need to name the specific Python version on the Bash command line by running manage.py directly, they'd work in your account too.

I think there is something wrong with my account. migrate does not work for me and errors out even when creating a new project.

What's the exact command that you are running, and the error message?

./manage.py migrate Unknown command: 'migrate' Type 'manage.py help' for usage.

./manage.py help
[auth]
    changepassword
    createsuperuser
[django]
    check
    cleanup
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    runfcgi
    shell
    sql
    sqlall
    sqlclear
    sqlcustom
    sqldropindexes
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlsequencereset
    startapp
    startproject
    syncdb
    test
    testserver
    validate

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

So I tried to install south but it states its installed. My next step was to add south to settings but then the application crashes.

Which version of Django and Python are you trying to use?

Also, can I take a look at your files? We can see them from our side, but we always ask permission first.

sure can. I just started and learning so I have no issues with it. I forgot to mention I will be going back to python 3.5 since you identified the issue was on my side.

OK, so it looks like you have a Python 3.4 project, which on PythonAnywhere right now will use Django 1.6. When you say "the application crashes" when you add south to settings, what exactly do you see?

It will show the stack trace of the errors but let me redo the project and try again.

So it worked like a charm. When I create a new app, do I just use ./manage.py createapp? Also, should I avoid using python before any command?

-Thanks

So it worked like a charm.

Great!

When I create a new app, do I just use ./manage.py createapp?

That's right.

Also, should I avoid using python before any command?

You don't need to use Python before any ./manage.py command, and it's generally safer not to.

The alternative is to make sure that you specify exactly which version of Python you want to use, which would be python3.4 for your current web app, but might be python3.5 or python2.7 if you create a new one with a different Python version.

The nice thing about not specifying it with the ./manage.py command is that you don't have to keep track of which particular Python version you used to create the web app. That's because it's already encoded in a "hashbang" line at the start of the file manage.py.

So....

Problem: Between chair and keyboard. Resolution: Educate the problem.

All jokes aside, I appreciate all the assistance you guys have provided me.

No problem, glad to help!

random note- after you do ./manage.py createapp, you also need to add that app to INSTALLED_APPS in your settings.py for django to see it.

.

RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not connect to server: Connection refused

Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

how can i clear this error?

For connecting with the MySQL db on PythonAnywhere, see: https://help.pythonanywhere.com/pages/UsingMySQL/.