django pycharm error : Process finished with exit code 1 - django

I'm new to web programming. I'm sorry if the question is ridiculous. A few days ago I put my code in the git branch, today I downloaded it from the directory I received using the git clone <git repo url> on my laptop. I've built ENV and installed this requirement. But whenever I run python manage.py runserver, I saw the error below:
Process finished with exit code 1
for more information : makemigrations and migrate works correctly.
How can I fix the problem? Thanks in advance for your guidance

You have to run two commands before running the server .These are:
python manage.py makemigrations
and
python manage.py migrate
These will create the database

Related

ImportError when using heroku for my django web

I checked django is installed properly and in my 'requirements.txt' I wrote 'Django==3.2.3'. However, I cannot use this code:
heroku run python manage.py migrate
So I checked this code:
python manage.py migrate
and found out it worked properly. I know that there are existing questions and read many of them, but I think I have tried everything I could do. I would be really grateful if someone can solve this problem.
your question isn't clear tbh.
install all the dependencies by using the pip freeze command and try to run your heroku commands in the heroku bash available in your heroku dashboard
to run the commands on your heroku machine from your CMD, then command is
heroku run bash --app your_app_name
then you can run whatever command you want.
but I am not sure what is the exact problem you are having.

Error in makemigrations and migrate in pycharm using django

Guy i was working on a django website i create a django website before also but this time when ever i run command
Python manage.py makemigrations
Its stop there no error nothing shows after this command
Suggest me what to do
And one thing i run the python makemigration blog
(Blog is app name here)
Its is working properly then but after this migrate command will hang
Detail : I created a project name blogs
And inside it i create a app blog
I am using postgresql database
After writing model class
I run the make migration command
And it shows nothing and no other command i can write after this as shown in image enter image description here
virtual environment using pipenv (follow below commands)
pipenv install django==3.0.1
then start the virtual enviorment
pipenv shell
then run your migrations command

Django Heroku : python: can't open file 'manage.py': [Errno 2] No such file or directory

I am deploying a Django website on Heroku. My project is called mysite-project which contains at its root manage.py and Procfile
I can visit the heroku website after I run git push heroku master.
And the website shows:
I am assuming I do not see anything (navbar, initial page, etc.) because I did not run migrate.
If I do:
heroku run python manage.py migrate
I get the error:
python: can't open file 'manage.py': [Errno 2] No such file or directory
Which makes no sense since I am in the right directory.
In fact:
I can run python manage.py runserver and locahost works
git ls-files manage.py --outputs--> manage.py
BUT
If I do:
heroku run bash
ls manage.py
I get:
ls: cannot access 'manage.py': No such file or directory
It seems that manage.py is in my local but not in my heroku.
Procfile
web: gunicorn mysite-project.wsgi
First use heroku logs --source app --tail to make sure that the Build succeeded.
If the build is successful, make sure you have your project at the root of the git repo.
I had the same problem because my Django project was not at the root of the git repo.
My file hierarchy was first like (assuming the name of the project prototype and it has one app named app)
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──new_folder
                ├──prototype (folder)
                ├──app (folder)
                ├──.gitignore
                ├──manage.py
                ├──db.sqlite3
I changed the hierarchy to the following and it worked
├──git_repo
        ├──Procfile
        ├──requirements.txt
        ├──prototype (folder)
        ├──app (folder)
        ├──.gitignore
        ├──manage.py
        ├──db.sqlite3
The welcome you see when you visit the site (as well as the fact, that you can't find manage.py with ls on the server) tells you, that you haven't successfully pushed your django project to Heroku yet. Try and run git push heroku master.
It may be that the push has failed, in which case you should consult the documentation. Specifically, run
$ pip install gunicorn django-heroku
$ pip freeze > requirements.txt
...and then add
import django_heroku
django_heroku.settings(locals())
...to the bottom of settings.py. Also don't forget to set STATIC_ROOT='staticfiles' in settings.pyaswell.
That screenshot attached indicates you have just created app in heroku but not pushed your local repository code to heroku app.
git push heroku master
I was getting this error too!
I solved it by specifying the path:
python <your_project_name>/manage.py migrate
This worked for me.
In my case, it was because I was using a branch name other than master. My branch name was heroku_branch, so to make things work properly, I pushed it this way
git push heroku heroku_branch:master
It was pushed this time and worked fine.
For django + heroku
web: python manage.py runserver 0.0.0.0:\$PORT

Heroku push does not upload migrations

I have developed a Django project and want to deploy it on a Heroku server. The problem is that my migrations are not uploaded after 'heroku push' command.
After I run
python ./Code/manage.py makemigrations
python ./Code/manage.py migrate
I see my migration files and database locally. But, after that, when I push them to Heroku, they seem not to be there. My website on Heroku gives the error that some tables are not available and when I run bash on the server to see my files there aren't any migration files and the migration folders in my apps only have the init.py file.
I even tried to make the migrations and migrate on the release phase. This is the Procfile:
release: bash ./release_tasks.sh
web: gunicorn --pythonpath Code Code.wsgi --log-file -
and this is release_tasks.sh:
python ./Code/manage.py makemigrations
python ./Code/manage.py migrate
Again, when I push to Heroku everything is ok and I see the correct migration messages, which shows that migration was successfully carried out. But still, there is no migration file on the server and my website gives the same error.
Here is what I don't understand:
screenshot
I have migrations locally and Git is up-to-date, but I don't have them on the server.
As with any code you create locally, you need to add it to git and then commit.
./Code/manage.py makemigrations
git add ....
git commit
git push origin heroku
You should remove the makemigrations step from the release tasks, there is no point running that on Heroku.

Django on Heroku - ProgrammingError at / relation "..." does not exist

I'm getting this error. I know you usually get this error because the databases wasn't properly migrated.
When I run heroku local web, the website works fine when I go to localhost:5000.
However after I deploy the app to heroku with git push heroku master, the error comes up.
In other words, it works in my local environment. But it does not work after deploying to heroku.
I have Heroku-Postgres installed as an add-on in heroku.
What could be causing this?
excute migrations and makemigrations in bash heroku. open the terminal in the local project folder and give the following commands:
heroku run bash
~$ ./manage.py makemigrations
~$ ./manage.py migrate
~$ exit
The following steps did it for me
Make all the necessary migrations (python manage.py makemigrations) and migrate (python manage.py migrate) locally,
push to heroku master
and finally running heroku run python manage.py migrate
Solved the issue
I experienced the same error after making a change to a model and then deploying this change to heroku.
The only way I managed to fix this problem was to do the following:
Reset the database in heroku
Delete the migrations files from the migrations folder for the broken app locally (but keep the directory and the __init__.py file)
Run python manage.py makemigrations and python manage.py migrate. This will repopulate the migrations folder with clean migration files.
Push changes to master (ensure that you do not have migrations directories in .gitignore files.
Deploy changes to heroku
Run the heroku shell heroku run bash
Run python manage.py migrate
I was able to do this because my tables did not have much data in, but I would try to avoid resetting the database if I had more data in my tables.