Strange error during initial database migration of a Django site - python

I have been working on a localhost copy of my Django website for a little while now, but finally decided it was time to upload it to PythonAnywhere. The site works perfectly on my localhost, but I am getting strange errors when I do the initial migrations for the new site. For example, I get this:
mysql.connector.errors.DatabaseError: 1264: Out of range value for
column 'applied' at row 1
'applied' is not a field in my model, so this error has to be generated by Django making tables for its own use. I have just checked in the MySQL manager for my localhost and the field 'applied' appears to be from the table django_migrations.
Why is Django mishandling setting up tables for its own use? I have dropped and remade the database a number of times, but the errors persist. If anyone has any idea what would cause this I would appreciate your advice very much.
My website front end is still showing the Hello World page and the Admin link comes up with a page does not exist error. At this stage I am going to assume this is related to the database errors.
EDIT: Additional information about why I cannot access the front-end of the site:
It turns out when I am importing a pre-built site into PythonAnywhere, I have to edit my wsgi.py file to point to the application. The trouble now is that I don't know exactly what to put there. When I follow the standard instructions in the PythonAnywhere help files nothing seems to change. There website is also seems to be very short on detailed error messages to help sort it out. Is there perhaps a way to turn off their standard hello world placeholder pages and see server error messages instead?

As it says in my comment above, it turns out that the problem with the database resulted from running an upgrade of Django from 1.8 to 1.9. I had forgotten about this. After rolling my website back to Django 1.8, the database migrations ran correctly.
The reason why I could not access the website turned out to be because I had to edit the wsgi.py file, but I was editing the wrong version. The nginx localhost web server I was using keeps it in the different folder location than PythonAnyhwere's implementation. I uploaded the file from my localhost copy and edited it according to the instructions on PythonAnywhere's help system without realizing it was not being read by PythonAnywhere's server. What I really needed to do was edit the correct file by accessing it through the web tab on their control panel. Once I edited this file, the website front end began to work as expected.

This issue occurred for me as well on version 1.10 with a brand new project. I found that if you use the recommended driver and the connector in the documentation, the migration works without issues.
If you don't feel like reading the docs, in breif:
Install MySQLdb for python 2.7 or mysqlclient for python 3.3+
Modify your settings.py file. In the DATABASES dictionary set:
'ENGINE': 'django.db.backends.mysql',

Related

How do I stop all of my projects redirecting to a specific URL?

I have been trying to learn Django to build a personal website where I can host some machine learning stuff I've made for others to use. In the process, I found this tutorial by Mozilla. I think what created the issue was the part saying RedirectView.as_view(url='catalog/', permanent=True). I was trying to make a simple function grapher for my site, so I used 'grapher/' instead of 'catalog/'. Now, that worked for what I was trying to do. Then I created a new django project to try some things from a different tutorial, and now when I try to run "py manage.py runserver" and go to http://localhost:8000, I still get redirected to http://localhost:8000/grapher/. This happens in all of my django projects, new and old.
Now, the really mysterious part to me was that when I tried deleting those projects AND the virtual environments I was using, then making a new virtual environment and project, I still get redirected http://localhost:8000/grapher/. I have also tried adding "path('', RedirectView.as_view(url='', permanent=True))," to my project.urls.py file which did not work. If there are some commands I can run to give more information, I would love to. I just don't know what other detail I can post since I deleted the projects. I just want to know how to change this redirecting behavior, and a bonus would be understanding better how the issue arose.
If RedirectView.as_view() isn't the issue, previously I had been working with static files changing STATIC_ROOT, STATICFILES_DIRS, and using collectstaticfiles.
Answer per Willem Van Onsem: permanent=True causes the browser to cache the redirect. Clearing the cache fixes it.

DisallowedHost error using PythonAnywhere

I'm new to Python and Django, and I'm following this tutorial to learn some Django basics. I keep getting a DisallowedHost error. (Screenshot: https://ibb.co/c1beYG)
As per this post, I added 'chocoberrie.pythonanywhere.com' to the ALLOWED_HOSTS list in settings.py, and I made sure to include it in quotation marks and keep the brackets. I even added it to requests.py, at line 113 (indicated in the error message).
Additional screenshots: https://ibb.co/jwUNnb and https://ibb.co/fbmrfw
I also committed the changes to Git, and I double-checked the repository to make sure that the URL was added to ALLOWED_HOSTS. I also made sure to reupload the changes on PythonAnywhere.
After all that, I'm still getting the error! It's really frustrating, and I don't know what else to do. Any help would be much appreciated!
Note: I did see a way to "disable" this error in this post, but I'm using a newer version of Django, so I don't know how to apply this.
I did the same tutorial! To solve this problem you have to go in the settings.py file of your django application. You will find ALLOWED_HOST setting which will be blank by default. Enter the following replacing your pythonanywhere name with your's:- '<your-pythonanywhere-name>.pythonanywhere.com'
now git pull in bash console and reload the website!

django stripe set up installation error

My problem is down to my lack of experience with django (and coding) and stripe.
I am trying to test a very basic stripe payment on a test form on my local development server, but I am getting an error message when I try to start my local development server.
Here is a a screen grab of the issue:
Can somone give me an idea of what I have done wrong and how I even start to go about solving the issue? I am using djstripe which I have pip installed.
I have searched my templates and gone over my code and SO and Google, but I am still stumped. I have djstripe installed in my INSTALLED_APPS.
Is there a tutorial of how to read and interpret the errors in the above screen grab, or does the understanding mainly come from experience?
You need to define STRIPE_PUBLIC_KEY (and STRIPE_SECRET_KEY I believe) in your settings.py. You can get this key from stripe if you have an account.
If you follow the instructions you will see this. https://github.com/pydanny/dj-stripe
A google search for "reading python stack trace" gives us this:
https://www.odoo.com/forum/help-1/question/how-to-read-and-understand-errors-from-tracebacks-9704

djangoappengine User Creation and Data Persistence is Broken

I recently updated to appengine SDK 1.6 and I'm having trouble with persisting data on my dev environment. I have everything setup according to the official installation guide.
Even though I had a super user account setup for my app previously, it no longer works. I created the account again with
manage.py createsuperuser
and it seems to do what it's supposed to but the admin login doesn't work. Also, every time I run
manage.py syncdb
The script keeps informing me that I just install the auth system and don't have any users yet. Then it prompts me to create a super user.
Because nothing is persisting, I can't login to the admin page and any data I attempt to save using the built in shell doesn't keep either.
is it possible that you fire up a new issue at the issue tracker https://github.com/django-nonrel/djangoappengine/issues or at the mailing list http://groups.google.com/group/django-non-relational ? I think there might be a bug somewhere.
Depending on what you upgraded from, it's possible that you previously had no 'default partition' value - earlier versions didn't set one by default, but recent ones use 'dev:'. Try giving a --default_partition argument to manage.py.
I didn't end up changing anything but after trying it again on my Win 7 machine the next day, the issue wasn't there so it unfortunately isn't reproducible right now. Maybe logging out and logging back in changed some type of state after the install, that's my best guess. Sorry that I don't have any further information.

Apache/Django freezing after a few requests

I'm running Django through mod_wsgi and Apache (2.2.8) on Ubuntu 8.04.
I've been running Django on this setup for about 6 months without any problems. Yesterday, I moved my database (postgres 8.3) to its own server, and my Django site started refusing to load (the browser spinner would just keep spinning).
It works for about 10 mintues, then just stops. Apache is still able to serve static files. Just nothing through Django.
I've checked the apache error logs, and I don't see any entries that could be related. I'm not sure if this is a WSGI, Django, Apache, or Postgres issue?
Any ideas?
Thanks for your help!
It sounds a lot like there's something happening between django and your newly housed database.
Just to eliminate apache from the mix, you should run it as the dev server (on some random port to stop people using it) and see if you still have issues. If you do, it's the database. If it behaves, it could be apache.
Edit, This looks interesting. You can test that by applying his patch (commenting out the .close()) but there are other similar bugs floating around.
Found it! I'm using eventlet in some other code and I imported one of my modules into a django model. So eventlet was taking over and putting everything to "sleep".

Categories