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

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

Related

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

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

Django - Make migration command detects changes but on migrating says 'No migrations to apply'

i am new to django developement after making changes to my model i tried to run the command python manage.py makemigrations my_app
it detects changes in my model and shows me the message
todoapp/migrations/0001_initial.py
- Create model confess
- Create model UserChoice
- Create model comment
but on executing python manage.py migrate my_appcommand i've got this message
No migrations to apply.
i usually do this after making changes in models, i don't know what happened now.
plss help me.
Firstly, try
python manage.py makemigrations my_app
python manage.py migrate
If this does not work and the project is still in development:
Delete migrations folder and pycache folder.
Delete db.sqlite3 (your database).
Make and apply migrations again.
I think this will work.
Delete all migrations files and __pychache__except__init__.py from your project and app. Also db.sqlite3 database then rerun makemigrations and migrate commands. It should solve your issue.

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.

Accidentally deleted my django south migration directory

I accidentally deleted the South migrations directory for one of my Django apps. This directory was not under git.
So now there are migrations in the database that are not present on the disk.
Some pointers on how I can recover from this will be much appreciated.
Without the option of any type of backup or finding the files somewhere, what you're going to have to do is make initial migrations and then fake them.
$ ./manage.py schemamigration app --initial
$ ./manage.py migrate app --fake
This will get you to where you are currently, however you won't have the option to migrate backwards.