During my experimentation with my blog app (blogapp
) in Django, I created two models (Category and Language), connected them to another model (Post
) using following connections:
category = models.ManyToManyField(Category)
language = models.ForeignKey(Language)
Then it gave an error like THIS due to the lack of default value. Tried to roll that back by using an amalgam of THIS and THIS. Then I tried to add a default value using THIS. I've got an error "django.db.utils.OperationalError 1050, Table XXX already exists"
, then I tried THIS. Tried to revert back migrations by deleting the created migrations from the migrations folder manually. At some point I got django (1054, "Unknown column in 'field list")
error.
Finally I decided to revert back to my original starting place. When I connect to my MySQL database using python manage.py dbshell
, I realized that my MySQL server still have two tables that should have been deleted, blogapp_category
and blogapp_language
. Server is working properly but I keep getting "Table XXX already exists"
error when I try to add those models.
Dropping tables from MySQL seems to be the only option at the moment. When I run
mysql> SHOW COLUMNS FROM blogapp_post;
I did not see any reference to language or category, i.e. no columns named language_id
or category_id
. I have two questions at the moment:
Is it safe to delete tables manually using:
DROP TABLE blogapp_language; DROP TABLE blogapp_category;
Will there be any negative effects?
- Is there a way to freeze database like git so that when I revert to the old database, such tables added to the database by django migrations automatically dropped??