You can probably just modify the migrations file after it is generated. Just move the statements around. I haven’t tested it myself. Saying that, why is the order of columns important to you? We don’t typically worry about the order of columns when working with databases.
From: [email protected] [mailto:[email protected]] On Behalf Of Vladislav Solovei Sent: Tuesday, August 28, 2018 8:05 AM To: Django users Subject: Foreign key auto-created column position in table Hil. I have a simple model: class SipPeer(models.Model): name = models.CharField(primary_key=True, max_length=40) type = models.CharField(max_length=10) defaultuser = models.CharField(max_length=40, blank=True, null=True) secret = models.CharField(max_length=40, blank=True, null=True) language = models.CharField(max_length=10, blank=True, null=True) call_limit = models.IntegerField(db_column='call-limit', blank=True, null=True) context = models.CharField(max_length=40) subscribecontext = models.CharField(max_length=40, blank=True, null=True) allowtransfer = models.CharField(max_length=20, blank=True, null=True) disallow = models.CharField(max_length=20, blank=True, null=True) allow = models.CharField(max_length=20, blank=True, null=True) host = models.CharField(max_length=40, blank=True, null=True) ipaddr = models.CharField(max_length=45) defaultip = models.CharField(max_length=20, blank=True, null=True) port = models.IntegerField(blank=True, null=True, default=0) insecure = models.CharField(max_length=20, blank=True, null=True) nat = models.CharField(max_length=40, blank=True, null=True) regseconds = models.IntegerField(blank=True, null=True) useragent = models.CharField(max_length=128, blank=True, null=True) lastms = models.IntegerField(blank=True, null=True) phone = models.ForeignKey(Phone, models.CASCADE, db_column='realnum', blank=True, null=True, related_name='peers', db_index=False) call_priority = models.IntegerField(blank=True, null=True) t38pt_udptl = models.CharField(max_length=40, blank=True, null=True) canreinvite = models.CharField(max_length=16, blank=True, null=True) fullcontact = models.CharField(max_length=255, blank=True, null=True) regserver = models.CharField(max_length=255, blank=True, null=True) deny = models.CharField(max_length=95, blank=True, null=True) permit = models.CharField(max_length=95, blank=True, null=True) qualify = models.CharField(max_length=6, blank=True, null=True) callbackextension = models.CharField(max_length=40, blank=True, null=True) setvar = models.CharField(max_length=40, blank=True, null=True) t38pt_usertpsource = models.CharField(max_length=40, blank=True, null=True) progressinband = models.CharField(max_length=5, blank=True, null=True) transport = models.CharField(max_length=24, blank=True, null=True) trustrpid = models.CharField(max_length=4, blank=True, null=True) class Meta: managed = True db_table = 'sippeers' After I do "make migrations" and "make migrate", the table column "realnum" is placed after all columns (but not between lastms and call_priority): | canreinvite | varchar(16) | YES | | NULL | | | fullcontact | varchar(255) | YES | | NULL | | | regserver | varchar(255) | YES | | NULL | | | deny | varchar(95) | YES | | NULL | | | permit | varchar(95) | YES | | NULL | | | qualify | varchar(6) | YES | | NULL | | | callbackextension | varchar(40) | YES | | NULL | | | setvar | varchar(40) | YES | | NULL | | | t38pt_usertpsource | varchar(40) | YES | | NULL | | | progressinband | varchar(5) | YES | | NULL | | | transport | varchar(24) | YES | | NULL | | | trustrpid | varchar(4) | YES | | NULL | | | realnum | int(11) | YES | MUL | NULL | | +--------------------+--------------+------+-----+---------+-------+ Can i somehow override this (default?) behavior? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To post to this group, send email to [email protected]<mailto:[email protected]>. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa1be9ed-985f-4946-a4ee-1254f3a206db%40googlegroups.com<https://groups.google.com/d/msgid/django-users/fa1be9ed-985f-4946-a4ee-1254f3a206db%40googlegroups.com?utm_medium=email&utm_source=footer>. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/990eca62471b4b58aced334727973414%40ISS1.ISS.LOCAL. For more options, visit https://groups.google.com/d/optout.

