Is it possible run makemigrations with deleted schema? - python

My all SQL schema was deleted cause of windows10 initialization.
So, I wanna run makemigrations with already existing django project code(with so many lines......).
But "python manage.py makemigrations" not works with error 'Table doesn't exist'... Is there some methods overcome these situations ???

Your existing migrations scripts are corrupt. So you need to do the following steps:
Delete the migrations folder inside your app
Then run makemigrations
python manage.py makemigrations
Apply the changes to DB
python manage.py migrate

Related

I can't make migrate back, after I deleted them in Django?

I am using Django with VSC.
I got some problem with my database, so i did want to delete inside of migrations but by mistake
i deleted directly folder of migrations. Anyway then i used the code;
python manage.py makemigrations
python manage.py migrate --fake
Then i got my migrations informations back. But the problem is, this time it didn't detect
my own migrations. So when i click something have connection with database. I got a mistake like
"No such table: MyMigrationsName"
How can i fix it ?
OP can create there a folder named migrations in the place OP deleted and an __init.py__ file inside of it.
Then, if possible, drop the current database and run
python manage.py makemigrations
python manage.py migrate
Right now you can DROP database, delete all migration files, run makemigrations and create a new database with the new migration files.
Then never make the same mistake again.
Try:
python manage.py makemigrations "your_app_name"
py manage.py migrate "your_app_name"'
Make sure the app name is included. This solved my problem.

My django code is requesting a table that doesn't exist

I tried to delete the 'db.sqlite3' file and do the migration again, but it didn't work
If you made changes to your model, you need to run python manage.py makemigrations. If this is a new project that you have never deployed to production, you can delete the migrations folder before running this command.
Then run python manage.py migrate.

how to fix django.db.utils.ProgrammingError:relation "some_object" does not exist?

How to fix django.db.utils.ProgrammingError: relation "some_object" does not exist?
I saw lots of topic on this platform to related this error, but won't able to fix it in my case.
In my case means, I am working on django and I have the postgresql database and It's working well but whenever I took pull request from git(where other person is working) and run the migration then I am getting this error.
below is some links that I had tried
https://stackoverflow.com/a/33055243/11360069 I just try but not working
https://stackoverflow.com/a/46697898/11360069
./manage.py migrate --fake default
https://stackoverflow.com/a/29672770/11360069
python manage.py migrate --run-syncdb and python manage.py migrate --fake appname
python manage.py migrate --fake, python manage.py migrate --fake--initial, python manage.py migrate
Only one way is working for me when I had create a new database and applying migration. But I am not sure that what will happen if, if I'll update this code on server then it will show same error then we can't delete or change the exiting database.

Django Heroku and postgresql

I am new to publishing django apps on heroku.
I have read their tutorials and figured I would start simple by modifying their template django project.
So far everything was good.
Then I made an app as one does, made a model and ran
python3 manage.py makemigrations my_app
python3 manage.py migrate
and things seemed ok.
I then pushed to heroku and there were no immediate complaints.
However, now when I try to make save a new model I get the error:
ProgrammingError at /my_app/
relation "my_app_myappmodel" does not exist
LINE 1: INSERT INTO "my_app_myappmodel" ("field1", "field2", "field3") VALUES...
odd...
So I run this locally and everything works fine.
I have tried cleaning my migrations, faking my migrations, squashing my migrations, etc (as other S.O. posts suggest)
Nothing works.
What is up and how do I fix it?
You need to actually run the migrations on Heroku once you have pushed the code generated by makemigrations. You do this via heroku run manage.py migrate.
run the following command from your terminal
heroku run python manage.py migrate
or you can also do:
in your local settings.py, change your DATABASES variable to use the heroku one then run from the terminal
python manage.py makemigrations
python manage.py migrate
but you should not normally locally make changes to the heroku production database (as in option 2) except if you are really desperate or don't care

Django 1.8 migrations not obeying routers in multi db setup

I have a django project with migrated and unmigrated apps. I can be able to selectively migrate the migrated applications by running the command :
migrate <app> --database <database>
However I can't do this for unmigrated applications which are thirdparty.
To be able to sync them I have to run the command without the specifying app
migrate --database <database>
This though ends up with errors from other apps to be routed to different databases complaining that no table is synced.
Is this there anything I can do to resolve the issue.
I appreciate the effort to answer this question.
I guess you can try
python manage.py migrate 'nameoftheapp'
In fact django keep track of the migrations scripts already done in your DB. To check if the list of really applied and non applied migrations run:
python manage.py showmigrations --list
You will see a big X next to the migrations that have already been applied.
If the thirdparty migrations scripts are already applied just delete them from the table django_migrations in you database (created automatically by Django). And apply your migrations again:
migrate <app> --database <database>

Categories