Forums

server error 500

please i need help with my site www.smartstuddy.com. it is a Q and A site. i just added a new library django-notifications-hq to enable notification on the site. now i am getting a server whenever i click on a question. an example of the error is given below.

i already ran makemigration and migrate commands after adding the library.

OperationalError at /question-detail/ac-circuit-containing-only-one-resistor-and-capaci/
(1054, "Unknown column 'homework_answer.notifications' in 'field list'")
Request Method: GET
Request URL:    https://www.smartstuddy.com/question-detail/ac-circuit-containing-only-one-resistor-and-capaci/
Django Version: 3.1.2
Exception Type: OperationalError
Exception Value:    
(1054, "Unknown column 'homework_answer.notifications' in 'field list'")
Exception Location: /home/Mecury/.virtualenvs/myenv/lib/python3.8/site-packages/MySQLdb/connections.py, line 259, in query
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.8.0
Python Path:    
['/var/www',
 '.',
 '',
 '/var/www',
 '/home/Mecury/.virtualenvs/myenv/lib/python38.zip',
 '/home/Mecury/.virtualenvs/myenv/lib/python3.8',
 '/home/Mecury/.virtualenvs/myenv/lib/python3.8/lib-dynload',
 '/usr/lib/python3.8',
 '/home/Mecury/.virtualenvs/myenv/lib/python3.8/site-packages',
 '/home/Mecury/sass/assignment']
Server time:    Sat, 19 Jun 2021 04:57:07 +0100

[formatted by admin]

What output do you get when you run manage.py migrate notifications?

i just did that and it says no migrations to apply. i am also thinking the error might be caused by the new notification field i added to my Answer model.

but when i ran manage.py migrate it was succesful and there was no error. i am just stuck and wondering why the error is occurring. i really hope this can be solved quickly.

Did you try to look at this table in a Django shell? Does it have all expected fields? Can you manipulate them manually?

when i do Answer.objects.all() or Answer.objects.get(id=1) in the python shell, i still get the same error as stated above. 1054, "Unknown column 'homework_answer.notifications' in 'field list'" . the notification is a boolean field in my answer model.

i did'nt get this errors when i was developing in my local machine

i am not accessing it from the shell.

Since there are differences between your local machine and PA -- could you, for the sake of experiment, use a fresh database on PythonAnywhere (simple sqlite should do), run migrations on that and check if the error still reproduces?

i have tried what you suggested. i used a sqlite database and everything works perfectly. migrations were run successfully and without any issues.

i am using mysql database in production offered by pythonanywhere. the error seems to be coming from mysql database. i guess mysql did not successfully run migrations for the new notification field i added to my answer model. i don't know why that should occur.

i really need help to get this solved thanks.

What was the exact order of actions you took? Was it an existing working project and you just add a new component or you started with a fresh MySQL database and run all the migrations at once?

It's an existing project that have been hosted on pythonanywhere for about five months. It's been using mysql database not a fresh one.

I just added a notification field to my Answer model, pushed it to gihub and then git pulled to pythonanywhere to update changes. I'm using django-notifications-hq library for the notifications. I ran migrations using mysql database on pythonanywhere and it was successful for the library. Unfortunately it seems the migrations didn't happen for the notification field for the answer model because of that I can't access the data for the answer model.

Are you sure that you have all of the migrations for the answer model on PythonAnywhere. If you did not commit the new migration on your local machine, then it would not be present on PythonAnywhere and so it would not be applied.

On my development machine I use sqlite and on pythonanywhere I use mysql. It's not the first time I'm making changes. I once made a change following the normal process and everything worked well. It's just kinda strange that this is happening. Everything has been working well until the recent update. I believe if the issue with the notification field is resolved then everything can be restored.

Normally if something like this occurs during development I will have to delete the database or migration files but I can't do this in production I guess as I will lose the initial data and it's not good for my site.

I guess you people have access to all the files and maybe you can have a look.

I'm stuck and frustrated.

When you're stuck and frustrated, it's time to recheck your assumptions. Check that you have the migration files that added the field to the database on PythonAnywhere. Check that you're using the database that you think you're using. Check that the structure of the database is what you expect it to be. Check that the code that you're running is actually the code you think you're running. Something that you believe to be true is not - debugging is the process of working out which of your beliefs is not correct.

i am sure i am using the correct database settings and the right code is running on pythonanywhere. i even tried a sqlite database on pythonanywhere as suggested by @fjl one of your staff and everything worked well.

do i need to git pull migration files from my github?? i thought you don't commit migration files to github.

what other alternatives and options do i really have??

You should commit migration files to git. See https://docs.djangoproject.com/en/3.2/topics/migrations/#version-control

well i was able to get the site working. i had to refactor my code and do stuff in a different way and still achieve my desired goal. now i can heave a sigh of relief. would have been crazy to have lost my database completely.

on a side note i feel admins on pythonanywhere can do better by responding a bit faster to issues and challenges on the platform. responses imo have been quite slow. thanks.

Glad to hear you got that working! And thanks for the feedback.

How was this issue resolved, I have the same problem

Is the problem that you have just a general 500 internal server error on your site? If so, you can start debugging by taking a look at the site's error log. There's a link on the "Web" page, and the most recent error will be at the bottom of the file.

Or have you already looked at the error log, and found that you are getting something more specifically like the exact error at the start of this thread? If so, it would help if you posted the full error.