[Solved]-Columns ordering in Django's model

8👍

On Django 1.8 this worked for me:

  • run ./manage.py makemigrations
  • edit the migration
  • reorder the fields list on migrations.CreateModel.

I did not test this with inheritance though.

2👍

Currently, there’s no built-in way to do this in Django.

I seem to remember a django-dev thread/ticket that discussed this, but I can’t see to find it at the moment. I’ll update this if I find it (and welcome anyone else to if they do.)

There’s probably a way to hack this into the core if you really need it that bad.

0👍

You could run django-admin.py sql which will print the SQL that creates the table for one or all apps, adjust the SQL to fit your needs and run it manually in some db shell of your choice!

0👍

Do you need to control the order of the fields in the database or just the way they are presented to the users? If the latter, there other options. For example, in the admin you can control the order of fields with fieldsets or fields.

Leave a comment