0

My production django-server uses postgres 12.12, django 32 and python 3.7. My test-server uses the exactly same software, but postgress 12.15.

After adding a new table 'etusivu_heroimg' I copied contents of the production postgres into my test postgres database and run python manage.py makemigrations and python manage.py migrate --fake.

The table was created and related features worked.

Then I checked that the production side had exactly same code as the test server before migration commands, even the app-specific migration-directories were same. But when I ran the migration commands on the production side the new table wansn't created.

(pika-env) [django@tkinfra01t pika]python manage.py makemigrations
Migrations for 'etusivu':
  etusivu/migrations/0003_heroimg.py
    - Create model HeroImg
(pika-env) [django@tkinfra01t pika]$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, conf, contenttypes, core, django_comments, etusivu, generic, kasitesivu, page_types, pages, redirects, sessions, sites
Running migrations:
  No migrations to apply.
  Your models in app(s): 'admin', 'auth', 'conf', 'contenttypes', 'core', 'django_comments', 'generic', 'page_types', 'pages', 'redirects', 'sessions', 'sites' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
(pika-env) [django@tkinfra01t pika]python manage.py makemigrations
No changes detected

However the django_migrations-table was changed on the production side, too and even some related permissions were :seen in the database dump:

INSERT INTO "public"."django_migrations" ("id", "app", "name", "applied") VALUES (55, 'etusivu', '0003_heroimg', '2023-05-25 14:26:29.780323+03');


 INSERT INTO "public"."auth_permission" ("id", "name", "content_type_id", "codename") VALUES (267, 'Can add Herokuva', 71, 'add_heroimg');

So I run the production-side database dump into the test-db, noticed that the fault repeated and added the missing table manually using the commands found from the database dump of the working db. Everything worked.

QUESTION: What should I do to fix the production ? Add the missing table manually or should I try to find more django-specific way to fix the problem ?

BTW: When I started the server [with the new code and the new table before migration-commands] using python manage.py runserver I didn't get any warnings about migrations; just noticed that the system crashed. That happened on both sides, test and production.

Jaana
  • 266
  • 1
  • 3
  • 14
  • 2
    The comment here is not help to fix the issue, But its tells the best way to do migrations,https://stackoverflow.com/questions/28035119/should-i-be-adding-the-django-migration-files-in-the-gitignore-file do make migrations in local, migrate and commit the migrations files , then in production only do 'migrate'. It make sure all the developers has the same migration files and less chance of migration conflicts. – Jisson May 26 '23 at 11:45
  • Exactly as @Jisson mentioned, dealing with migrations can be tricky, especially when dealing with a production server. So again as Jisson mentioned, do it locally then only migrate to production. – Emad G May 26 '23 at 13:57

0 Answers0