0

I understand that Django handles database creation using migrations files and that any changes to the table are carried out using ALTER statements in a new migration file.

My question isn't django specific:

Would an initial CREATE followed by multiple ALTER operations on a table affect the performance of the table in any way? What if data was inserted in the intermediate stages?

Would it be better to do a dump of the latest schema and data and execute a single CREATE instead?

I initially thought that it would be better to not commit migrations to github since they're derived from the models.py files anyway. Now i realize that standard practice is to keep updating the migrations on github. Is there any reason this method is preferred to running makemigrations with the updated model files?

2bigpigs
  • 452
  • 3
  • 12
  • Migrations are useful when you have data in your tables you'd like to keep around. – NightShadeQueen Jun 28 '15 at 21:05
  • We're early in the development stages. There is initial data in the databases but those can be added just before deployment. Till then i've just been populating them with dummy data from a script. I can see a flaw with my approach. If i change the model, I may have to rewrite the script. That won't happen with data migrations since it respects the order in case of dependencies. What about the second part of the question? is it better to drop and recreate the table or is continously altering it acceptable? – 2bigpigs Jun 29 '15 at 13:00

1 Answers1

0

If your code already deployed and there is some client data - you need commit migrations ... same applies if you are working with legacy database ... in other cases don't do this.

But if you plan to deploy your project - last commit should be initial migration.

And if you afraid that some user data will be lost while migration you should check docs of your database management system ... but almost cases alters a table’s structure with blocking reads or writes.

ALTER TABLE without locking the table?

Community
  • 1
  • 1
madzohan
  • 11,488
  • 9
  • 40
  • 67