id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 24203 Optimisation: adding multiple fields to same model should attempt to run single ALTER TABLE statement Peter Lauri nobody "Origin: https://groups.google.com/d/msg/django-users/DDekrNgXH2U/k1un-e8CbnMJ When adding multiple fields to a Model the makemigrate and migrate does not attempt to create one ALTER TABLE statement, but rather one per field added. This can cause slow migrations of large tables. I propose to optimise to attempt to merge multiple AddField to one single ALTER TABLE request when the migrate is run. My real world case the db backend was MySQL, here is PG example of 2nd migration db output after adding two fields to one model. {{{ Applying play.0002_auto_20150122_1825...DEBUG ALTER TABLE ""play_play"" ADD COLUMN ""field2"" varchar(100) NULL; (params []) DEBUG (0.000) ALTER TABLE ""play_play"" ADD COLUMN ""field2"" varchar(100) NULL; args=[] DEBUG ALTER TABLE ""play_play"" ALTER COLUMN ""field2"" DROP DEFAULT; (params []) DEBUG (0.000) ALTER TABLE ""play_play"" ALTER COLUMN ""field2"" DROP DEFAULT; args=[] DEBUG ALTER TABLE ""play_play"" ADD COLUMN ""field3"" varchar(100) NULL; (params []) DEBUG (0.000) ALTER TABLE ""play_play"" ADD COLUMN ""field3"" varchar(100) NULL; args=[] DEBUG ALTER TABLE ""play_play"" ALTER COLUMN ""field3"" DROP DEFAULT; (params []) DEBUG (0.000) ALTER TABLE ""play_play"" ALTER COLUMN ""field3"" DROP DEFAULT; args=[] }}}" Cleanup/optimization new Migrations dev Normal migration Markus Holtermann ambivalentno dharris+django@… emorley@… Phil Krylov Adam Johnson elonzh Someday/Maybe 0 0 0 0 0 0