As the title suggests, even if I migrated from Django, it was not reflected in the DB and I suffered, so I will record it.
・ Windows10 Enterprise -Docker Desktop for Windows: 2.1.0.1 ・ MySQL: 5.7.28 (on Docker) ・ Django: 3.0 (on Docker)
When I added a new model (referred to as ** model A **) to models.py and migrated it, it was not reflected in the DB. Since changes in other models are reflected, it is estimated that only ** model A ** is a problem.
I tried various things with reference to the following articles.
・ What to do if you're migrating with Django but it's not reflected in your DB [Django output] How to reset Migrations with Django (keeping the existing database) ・ I can't migrate with django ・ Reflection of Django's models.py (python manage.py makemigrations / migrate) Phenomenon that column is added to model but not added to migration file ・ What to do when python manage.py migration doesn't work [Django]
Generally, it was said that if you delete the migration history with "python manage.py migrate --fake hoge zero", delete the files in the folder, then make migration and migrate, it will be reflected, but it is wiped out.
So, once I drop the DB and try to migrate again ... ** Model A ** and another model (** Model B ) are not reflected. When I read "models.py" with a good feeling of "?", Only these two models have the characters " managed = False **" in "class Meta:".
models.py
class Meta:
managed = False
db_table = 'temp'
I deleted it and migrated it again, and it was done. Easy. I just didn't understand the basics. ** Model B ** is pasting the format copied from somewhere, and I copied and pasted this to create ** Model A **, so it seems that I got caught in this trap. By writing "managed = False", it seems that migration will not be managed. That shouldn't be reflected. (I wrote in "History" that the changes of other models were reflected, but I did not try it with ** model B **)
It is a mystery why the copy source included this, but since it worked for the time being ... Under lighthouse living. I decided to look it up a little closer.
Recommended Posts