11
You have squashed the migrations, so one of the dependencies that 0016_auto_<date2>_<time2>
had is now part of the newly created squashed migrations. Meanwhile the 0016_auto_<date2>_<time2>
has already been run and now you’re trying to run the squashed migration.
I personally don’t know if there’s any way to fix this automatically. You will need to fix the issues yourself. If you have version control, revert these changes and try to rethink how you should squash the migration without affecting old ones.
71
This worked for me. I thank my coworker for sharing this knowledge after I searched online for many hours.
Start your db shell
python manage.py dbshell
Use the database you want. If you don’t know, run .databases
(SQLite) or SHOW databases
mysql>use <database_name>;
Retrieve all the migrations under your app
mysql> select * from django_migrations where app='<app>';
You will see the output with ids next to all migrations. You may want to drop the migration that was applied before its dependency: <appname>.0016_auto_<date2>_<time2>
. Say its id
is 361
:
mysql> delete from django_migrations where id=361;
Now out of the db shell, run python manage.py migrate
again.
- [Django]-Django csrf token + Angularjs
- [Django]-Django: Example of generic relations using the contenttypes framework?
- [Django]-Forbidden (403) CSRF verification failed. Request aborted. Reason given for failure: Origin checking failed does not match any trusted origins
16
I have solved this problem when i did (custom user model) by this steps:
-
delete this file :
migrations\0001_initial.py -
delete this :
db.sqlite3 -
put this code in settings.py :
AUTH_USER_MODEL = ‘users.CustomUser’ -
Then do (makemigrations) then (migrate )
-
run server .. the problem solved
i have used this link it is help me to solve the problem of dependency :
https://docs.djangoproject.com/en/3.1/topics/auth/customizing/
Due to limitations of Django’s dynamic dependency feature for swappable models, the model referenced by AUTH_USER_MODEL must be created in the first migration of its app (usually called 0001_initial); otherwise, you’ll have dependency issues.
In addition, you may run into a CircularDependencyError when running your migrations as Django won’t be able to automatically break the dependency loop due to the dynamic dependency. If you see this error, you should break the loop by moving the models depended on by your user model into a second migration. (You can try making two normal models that have a ForeignKey to each other and seeing how makemigrations resolves that circular dependency if you want to see how it’s usually done.)
- [Django]-Django template tag to truncate text
- [Django]-How to set the default of a JSONField to empty list in Django and django-jsonfield?
- [Django]-Gunicorn Connection in Use: ('0.0.0.0', 5000)
6
run this python manage.py dbshell
INSERT INTO public.django_migrations(app, name, applied)
VALUES ('YOUR_APP_NAME, '0017_<modelname>_squashed_0019_auto_<date3>_<time3>', now());
and you should be fine. If Your migration was changing a lot to the database, then I am afraid it won’t be that easy to fix it.
- [Django]-Filtering dropdown values in django admin
- [Django]-Querying django migrations table
- [Django]-How can I get the full/absolute URL (with domain) in Django?
2
- Edit the dependencies of the conflicting migration, so that it no longer references the already applied migration.
-
Then run python manage.py migrate again and it should be fixed.
- Warning: this only work suppossing that the state of the database matchs the state you get having applied the conflicting migration.
- [Django]-How to debug Django commands in PyCharm
- [Django]-When should I use a custom Manager versus a custom QuerySet in Django?
- [Django]-How do I remove Label text in Django generated form?
2
you need to fake migrations and migrate again
just make sure that you have a backup from your data because when you migrate again you need to delete apps table.
make sure that you look at show migrations and migrate un migrated apps by its sequence
- [Django]-Differences between STATICFILES_DIR, STATIC_ROOT and MEDIA_ROOT
- [Django]-How to get the currently logged in user's id in Django?
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
0
I had the same issue on 2020 with Django 3.0.6.
I tried all the relevant answers with no success. So I went in my database and deleted all the tables. You must export the relevant tables if you have done lot of work. I mainly delete django files in my database. And after, run:
python manage.py makemigrations <my-app>
And:
python manage.py migrate
Export your relevant tables if any.
- [Django]-Django: Redirect to previous page after login
- [Django]-Substring in a django template?
- [Django]-Python (and Django) best import practices
0
- First back up your database before resolving the conflicts, (Use "
python manage.py dumpdata > db.json
" for SQLite). - Execute
python manage.py dbshell
, to access the database. - Delete the migrations rows that are having conflicts from the django_migrations table.
- Rename the tables conflicting in the database
- Execute the makemigrations and migrate commands
- After successful migrations, Drop the newly readded tables and finally restore the previously renamed tables to match the migrations need
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
- [Django]-How to specify the login_required redirect url in django?
- [Django]-ImportError: cannot import name '…' from partially initialized module '…' (most likely due to a circular import)
0
I had the same problem, and here’s how I solved it.
The following is my error message
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 327, in check_consistent_history
raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration aaaa.0024_campaign_template is applied before its dependency bbbb.0005_templatemodel_from_template on database 'default'.
My solution
python manage.py migrate bbbb
python manage.py migrate
Because I changed the Django’s app name in batches, the application order was not consistent when applied to the database. The bbbb that aaaa relies on was not created first, so I manually created the bbbb first
- [Django]-On Heroku, is there danger in a Django syncdb / South migrate after the instance has already restarted with changed model code?
- [Django]-Proper way to handle multiple forms on one page in Django
- [Django]-Django won't refresh staticfiles
0
Migration file is not created for all app:
step 1:
create migration folder and add __init__.py file for all app
step 2:
delete db.sqlite3 database
step 3:
python manage.py migrate
python manage.py makemigrations
- [Django]-How can I see the raw SQL queries Django is running?
- [Django]-Google Static Maps URL length limit
- [Django]-Django URLS, how to map root to app?
-2
- Delete all of your migrations folder
- Delete the database(sqlite3)
Then run the makemigrations
and migrate
command
- [Django]-How to iterate through dictionary in a dictionary in django template?
- [Django]-How do I convert a Django QuerySet into list of dicts?
- [Django]-Django 1.4 timezone.now() vs datetime.datetime.now()
-9
-
Delete the migration files.
-
Run:
python manage.py migrate python manage.py makemigrations python manage.py migrate python manage.pyrunserver
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-Aggregating save()s in Django?
- [Django]-How to add url parameters to Django template url tag?