Django rolling back migration doesn't do anything. Table is still present - python

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.

Related

Unable to apply migrations to Heroku postgres database

The database is postgres and framework is django.
Running migrations works fine on localhost but not on Heroku server. I cannot drop or reset the database because it contains important data. I backed up the database, reset it and all migrations worked, but when I restored the backup, it reverted back to the old migration state and the problem persisted.
I don't know how to transfer only the data from the backup into a reset database instead of also transferring the old database structure.
When I run heroku run python manage.py migrate I get this error:
No migrations to apply.
Your models in app(s): 'app1', 'app2', 'app3', 'app4', 'users' have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Using heroku run python manage.py makemigrations app-name does not help either.
Is there a way to map and transfer just the user data from the old database into the new one? Or is there a way to brute force the old database to accept the new migration structure?
I would be glad if I get some help. Thanks.

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.

Stop Django background-task from deleting completed_task model

On django-background-tasks==1.1.11 (Django==2.2, Python 3.6.9), I have this problem where everytime I run python manage.py migrate, the table background_task_completedtask gets deleted. This breaks my background tasks. So far I have found a way to reverse it, as it is a separate migration from the initial one, meaning I can just python manage.py migrate background_task 0001_initial to restore it, but this does mean it will still be removed next migration.
Any ideas for a more permanent solution?
Found a (somewhat hacky) permanent solution myself:
By faking migrations (python manage.py migrate --fake (or python manage.py migrate appname --fake)), you make django think the migration has been executed without actually executing it. By doing this with the migration that was bothering me, I managed to get everything working again.

Django-Cms and Django-shop migration issues

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'

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