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>
Related
I am running the following command to rollback my migration in my Django project.
python manage.py migrate users 0021_emailsetting
The issue is that there is no effect after this command is executed. I get following result:
Operations to perform:
Target specific migration: 0021_emailsetting, from users
Running migrations:
No migrations to apply.
The table is still there in the database and showmigrations also checks that particular migration as applied.
I had applied python manage.py migrate users zero to make sure there isn't any previous migration causing the issue but the issue still remains after running all migrations after full rollback.
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 started creating my website on my own PC using the Django-cms install script then I tried to add a lot of applications such as Django-Helpdesk and others and everything was smooth until I tried to add pieces of djangoSHOP demo project and dependencies to email_auth.
Then I started to have report that the migration history was inconsistent and migrations applied out of order.
Before adding djangoShop to the installed apps, I just add the following commands to setup the DB:
manage.py migrate --run-syncdb --noinput
manage.py migrate --noinput
and everything was ok.
Now, as I'm just starting, I don't have changes to the schema to apply but most of the django apps I try to install have migrations folders with several migrations.
I don't want to update an existing schema, I want to create a new one.
I'm working from a blank database so do I really need to apply all those migrations ? To me it seems that the default behaviour of running migrations is not compatible with starting from a blank db,
I don't understand what to do just initialise the database to just have the required tables created.
Did anyone got the same kind of problems?
How did you fixed it?
Edit:
django-cms>=3.5,<3.6
Django 1.11.19
Error message:
Django InconsistentMigrationHistory: Migration Helpdesk.000xxxxx.py is applied before its dependency email_auth.0001_initial.py on database 'default'
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 was trying to alter something on my user model in django and in the process I used makemigration to generate the migration file for it. But then decided against the whole thing, but now I have an unmigrated migration file located somewhere and I can't find it. I don't have an auth migrations folder in my app and I looked in the django auth migrations file and it's not there either. It shows up when I run python manage.py showmigrations as unmigrated, but I don't see the file anywhere. It doesn't show up when I do git status either.
Now I'm stuck because I can't run migrate without it trying to migrate it and erroring. This is probably something silly that I'm overlooking. :-/
You can either delete the table manually or inspect all migrations with:
./manage.py showmigrations my_app