If I use mongodb in django project with the help of djongo third-party api should I have to use commands migrate and makemigrations again n again when ever I make changes in my models??
Related
I install mysql as my database in my django project.
I did makemigration and migrate it on the django.
After that I wanted to try to run the server, but the python manage.py is not working at all even if there is python stored in my computer.
python_version_in_cmd
I have the screenshot here where it shows no response at all but pip is responding. django
This is my computer environment path computer enviroment path
When I was installing mysql the mysql/python was failing, is that the problem? any hints?
What is the error when running python manage.py runserver? Not knowing that, I could make some guesses.
Make sure your models are setup correctly.
After you get your models written, you can run python manage.py makemigrations
Then you need to run python manage.py migrate in order for the models to be applied to the database.
Some guidance can be found here: https://www.geeksforgeeks.org/django-migrations-python/
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.
I use django-admin startproject to create a new project, then use python manage.py migrate.
I find there are some tables will create by default.
I want migrate my tables only when I run python manage.py migrate. Is it possible to skip the default?
By default, INSTALLED_APPS contains django.contrib.admin and django.contrib.auth apps (along with few other apps). These apps are part of Django. These apps are optional, and can be removed if you do not need functionality they provide (See: Run django application without django.contrib.admin).
python manage.py makemigrations will create the migrations files for all the changes to models in all the apps.
And python manage.py migrate will apply previously computed migrations to the database.
When you have multiple apps, use python manage.py makemigrations [app_name], and python manage.py migrate [app_name] to limit these operations to specific app.
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
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>