Issue
I'm developing an app changing the models a lot. I created a table, changed the fields, and since it's only play data there was no point in keeping it.
So I did:
python manage.py dbshell
sqlite> .table
auth_group django_admin_log
auth_group_permissions django_content_type
auth_permission django_migrations
auth_user django_session
auth_user_groups products_produit
auth_user_user_permissions
sqlite> DROP TABLE products_produit
...> ;
sqlite> .table
auth_group auth_user_user_permissions
auth_group_permissions django_admin_log
auth_permission django_content_type
auth_user django_migrations
auth_user_groups django_session
Table products.produit
is indeed gone. I also delete migration files (e.g. 000X_.py). There are indeed no more migration files under /migration/, only __init__.py
.
I updated my model and re-ran make migrations:
Migrations for 'products':
products/migrations/0001_initial.py
- Create model Produit
Process finished with exit code 0
It created the migration, I see all expected fields. However, when I ran migrate nothing happened:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, products, sessions
Running migrations:
No migrations to apply.
Process finished with exit code 0
The table still isn't there:
sqlite> .table
auth_group auth_user_user_permissions
auth_group_permissions django_admin_log
auth_permission django_content_type
auth_user django_migrations
auth_user_groups django_session
sqlite>
There is some trace left of the former table, even though it was dropped. What do I need to do if I want to drop the table to completely start anew?
The issue isn't with my new model because makemigrations succeeded and if I remove the db.sqlite3 file (and create a superuser anew etc.) the product.produit
table is migrated as expect.
Solution
Django adds a table to your database to manage what has been migrated. You can see the table django_migrations
. You are in the situation that you deleted the table yourself, while the entry for it's migration was left in django_migrations
. To fix this the simplest way would be to fake a migration to zero:
python manage.py migrate --fake products zero
Answered By - Abdul Aziz Barkat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.