0

So I started working on a project that is right now on production but the preovious dev kinda made a mess with migrations (or maybe I am wrong), the migrations in developement and in production are not the same (he gitignored them) and I can not start working because there are missing migrations in development so the database is no fully migrated.

Im thinking I can just delete all migrations in development, reset them but I don't think that is a good idea in production. What should I do?

  • Have you copied the migration-files to your production environment? Apply your files with `...migrate` and restart your server. With `python manage.py showmigrations` shows which files have been applied or not. – Klim Bim Apr 29 '21 at 14:07
  • If your schema is corrupte, then install `django-extensions`. You can use `reset_db` for creating a new schema. For instance, it is necessary, if django does not adjust fields properly e.g. `UUIDField` to `IntegerField` – Klim Bim Apr 29 '21 at 14:17
  • But reset_db will empty the database isnt it? – Enrique Uzcategui Apr 29 '21 at 14:26
  • Yeah, it empties your db. You can run `dumpdata` for saving your data and `loaddata ` for restoring. – Klim Bim Apr 29 '21 at 14:46

1 Answers1

1

Migrations have two purposes: 1. Creating schema of database, 2. Migrating existing data of database (For example when you change a field from IntegerField to CharField, you need to write some migrations to convert integers saved in database to their equal char.) This one is only needed for production. If you are missing these migrations, it is not a problem, Because you only need schema of database to develop. But how can you make sure you have the correct schema? Run python manage.py makemigrations and then python manage.py migrate. You are good to go and there is no need to delete any prior migrations.

  • I ran it in develop but it seems that not all migrations are being applied, I get ProgrammingError all the time. – Enrique Uzcategui Apr 29 '21 at 14:25
  • ProgrammingError at /dashboard/inspecciones/list column inspection_inspection.principal_company does not exist LINE 1: ...reated_at", "inspection_inspection"."updated_at", "inspectio... ^ – Enrique Uzcategui Apr 29 '21 at 14:33
  • Maybe this help: https://stackoverflow.com/questions/42613536/django-programming-error-column-does-not-exist-even-after-running-migrations – Mohamad Malekzahedi Apr 30 '21 at 07:31