Issue connecting PostgreSQL db to Heroku - python

I am currently trying to deploy a Python/Django app to Heroku. The build was successful however, I am attempting make a migration to an established postgresql database to connect it to Heroku remote.
When I run:
heroku run python manage.py migrate
I get the following error:
ImportError(
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?
The Django environment is currently activated in my terminal screen.
I ran python to get the version type then ran print(sys.path which showed the Django environment listed. Just for giggles I ran pip install django once again, where a message stating requirement already satisfied came up.
So it looks like django is installed, my virtual environment is working, but I cannot make the migration for Heroku...
Any advice appreciated.

Related

no errors thrown when running pipenv install, but running a python manage.py migrate after results in errors

ModuleNotFoundError: No module named 'django_on_heroku'
I've got a new machine at work and I'm attempting to run an old project which I've cloned. Cannot get the api server up and running.
(ps, my first stack overflow post -- sorry if the format isn't great or specific enough!)
Have tried installing django on heroku in the pipenv - that is sucesfull, the error reoccurs though on the next dependency when i attempt a migrate and then run server.

Pythonanywhere Django app does not work with MySql

What do we have:
Django app hosted on Pythonanywhere with sqlite db initialized
MySql DB activated on Pythonanywhere (it provided me with db name, pasword and host - everything that I need to setup settings.py)
pip install mysqlclient finished successfully
python manage.py makemigrations - DONE
python manage.py migrate - DONE
mysql console on Pythonanywhere shows all my tables created
but restarting app causes pythonanywhere error page and link to error log
2020-08-15 17:22:56,536: Error running WSGI application
2020-08-15 17:22:56,569: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
2020-08-15 17:22:56,569: Did you install mysqlclient?
So the question is how could it be possible? As i got it right migrations are used mysqlclient to manipulate DB, how can it be not installed?
Might be someone did face with similar issue?
you need to install mysql client, but that might also throw an error, so you need to install it using its wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient and keep installing every wheel incase an error occurs.

Django "settings are not configured" error and cannot define environment variable DJANGO_SETTINGS_MODULE

This error is easy to reproduce. Basically just start a new django project and run the server with django-admin. I read many StackOverflow posts and tried multiple methods but did not work. Here are the detailed steps to reproduce:
Created new directory named testproject
pipenv install django
Started new project named test with the django start project script
pipenv shell
django-admin runserver
Error: "django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
Typed this in ubuntu as suggested in the official django docs: export DJANGO_SETTINGS_MODULE=test.settings
django-admin runserver
Got a giant line of error followed by ModuleNotFoundError: No module named 'test'. However, if i do django-admin runserver --pythonpath=. --settings="test.settings" the server successfully runs.
I know I can just use python manage.py to start the server but my project uses Django cache framework and when I try to access the cache the same settings are not configured error is thrown. Trying to understand what is going on, any help would be greatly appreciated.
In your list I did not see the virtual env activation.
Did you activate the virtual env ?
'''
source activate testproject
'''

"ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure

After I tried to deploy my Django website on Azure, I got an error saying:
ModuleNotFoundError: No module named 'django'
I added a requirements.txt in the root directory of my Django project, am I missing anything else? I've tried to install Django from Kudu BASH but it gets stuck on "Cleaning Up".
Here is the full error: https://pastebin.com/z5xxqM08
I built the site using Django-2.2 and Python 3.6.8.
Just summarized as an answer for other people. According to your error information, I can see that you tried to deploy your Django app to Azure WebApp on Linux based on Docker. So there are two offical documents will help as below.
Quickstart: Create a Python app in Azure App Service on Linux
Configure a Linux Python app for Azure App Service
The error ModuleNotFoundError: No module named 'django' indicated that there is not django package installed on the container of Azure Linux WebApp.
Due to the content of Container characteristics of #2 document above as below,
To install additional packages, such as Django, create a requirements.txt file in the root of your project using pip freeze > requirements.txt. Then, publish your project to App Service using Git deployment, which automatically runs pip install -r requirements.txt in the container to install your app's dependencies.
So the possible reason is the requirements.txt file not in the corrent path of your project or container after deployed, which path should be /home/site/wwwroot/requirements.txt on the container or the root of your project like the offical sample Azure-Samples/djangoapp on GitHub.
I had the same problem. requirements.txt was in my repository, but randomly I started getting the same error ModuleNotFoundError: No module named 'django' after changing a setting or restarting the service or something. Nothing I could do, change the setting, or reboot repeatedly fixed it. Finally what worked for me was this:
Make a small change to the code and commit it, and push it up to the app service.
This fixed it for me. It has happened a couple times now and every time this solution has worked for me. It seems like the App Service sometimes gets in this state and needs to be jostled with this trick?

How can a django project detect if the system has django installed?

I've built a small project on my system.
After building the project, I put it on a USB drive, and copied to another system.
When I run the project, how can it detect if django is installed in the system or if the system has all of the the requirements for the project?
For example, I made a blog example project on a laptop, then copied that project(blog) onto a USB drive and then I copied that project(blog) to my own system. After copying, I tried to run the project. If django is installed then the project runs successfully. But when django is not installed it gives an error in the terminal.
How can the program detect if the required (Django/Python) is installed or not?
Simply the module won't be found when you try to run your project.
You can run 'python' in your command line and try to 'import django' if it returns an error then django isn't found it means that django isn't installed on the current machine.
When you will try to run your Django project you will get ImportError and i think it is the detection that django is installed or not.
ImportError: No module named django
Into your project you can write a new management command to check that in system django is installed or not.
and you can run like .
python manage.py is_django_installed
even you can customize your runserver/migrate/syncdb management command to check that django is installed or not .

Categories