when migrating django codes to the database Errno 2 No such file - django

I am connecting my database with Django codes so when I use
python manage.py makemigrations I get the error as no such file
py manage.py makemigrations
C:\Users\selwy\AppData\Local\Programs\Python\Python310\python.exe: can't open file 'C:\Users\selwy\projects\manage.py': [Errno 2] No such file or directory
PS C:\Users\selwy\projects>

This can be solved with these steps :
Delete your database (db.sqlite3 in my case) in your project directory.
Remove everything from pycache folder under your project subdirectory.
For the application you are trying to fix, go to the folder and clear migrations and pycache directories
When you are sure you have cleared all the above files, run:
python manage.py makemigrations
python manage.py migrate
For further references,visit:
Django - no such table exception

Related

Django.Programming Error: Table Name Does Not Exist - How to solve?

I deleted a model in Django which I created for testing purposed. Now when I try and run makemigrations and mirgrate I get the following error:
django.db.utils.ProgrammingError: table "members_test" does not exist
Is there a standard procedure I should be doing when deleting a model? I only deleteed the code out of my Models file and tried migrating after.
I've only tried runing migrate and make migrations in addtion to scouring the web.
Simply you can delete all migrations folder and re-migrate using below command:
python manage.py makemigrations appname
python manage.py sqlmigrate appname 0001
python manage.py migrate

Django.db.utils.ProgramingError Relation doesn't exist

I am using Django3 and Postgres as Database, I clone the old project using Django and postgres, I cloned and setup the virtual environment for my project.
At the time of runserver, its throws me the error of
Django.db.utils.ProgramingError realtion "Table name" doesn't exist
There was the migrations file in the project when I cloned it, but I removed them, so can create my own, but this error still there, even I remove the migrations folder, but its still there and can't create my own migrations and not even start the server.
I tried it with cloned migrations files and without it but can't runserver
Run this command python manage.py showmigrations
Remove the actual migration files
Go through each of your projects apps migration folder and remove
everything inside, except for the init.py file
Then run python manage.py makemigrations

OperationalError at /admin/login/ even after making migrations

I have made migrations still i am getting this error . I have tried deleting the database and making it again. I have tried making migrations again and again but problem is still there.
OperationalError at /admin/login/
no such table: auth_user
Note
python manage.py makemigrations
python manage.py migrate
i have used both
Try deleting the migrations folder but don't delete init.py file. After this, run the commands:
python manage.py makemigrations
python manage.py migrate

No table created in db.sqlite3 after migrate and makemigrates in Django

I did this command and after that, only the DB file was created without any tables.
python manage.py makemigrations
python manage.py migrate
also I use the app name in this commands but nothing changed.
After that, I saw this DB file:

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.