How to move django models to new server

I have two options and not know which is the best:

1 - After coping Django files, delete migration files, so after makemigrations and migrate tables will be created. And after that import dumped database (only data). or

2 - Import dumped database (full), everything (create tables and data).

In my opinion, move project with migration files is better, because you copy all lifecycle of developing, then you can just update database using existing migrations. Also, you will have option to rollback to previous migration on new database or do retrospective on bugs using migrations. If you make migration on moved database you will lose those oportunities

chatGPT says option 2 is better

Option 2 is typically better because it preserves the existing database schema, data, and migration history, ensuring consistency. You simply dump the full database (schema + data) from the old server and restore it on the new one, then update Django settings to connect to the new database. This approach avoids complications with regenerating migrations and ensures Django recognizes the current database state.

Option 1 involves deleting migration files, recreating the schema with makemigrations and migrate, and importing only the data. While it provides a clean schema, it can be error-prone, especially for complex data relationships, and removes migration history, which may cause tracking issues later.

Choose Option 2 for established projects with significant data and synchronized migrations. Use Option 1 only if the migration files are problematic or outdated, and you’re confident in handling potential data integrity issues.

Вернуться на верх