1👍
No, there’s no way for you to insert column between other columns without creating new tables. But I couldn’t figure out the reason to have columns(model fields) in particular order, it doesn’t make sense. In fact, I really doubt that there’s any sql statement could directly reorder the column sequence for database schema.
0👍
As you rightly guessed this is going to need a bit of custom sql which can be executed with RunSQL. That means you need to edit the generated migration file as follows:
operations = [
migrations.RunSQL(
"ALTER TABLE musician ADD COLUMN name varchar(255) NOT NULL;",
state_operations = [
migrations.AddField(
model_name='chat',
name='tags',
field=models.CharField(blank=True, max_length=100, null=True),
)
]
]
👤e4c5
0👍
Shang Wang: "I really doubt that there’s any sql statement could directly reorder the column sequence for database schema."
You are completely wrong!
ALTER TABLE CoreDB.country CHANGE column_to_move AFTER column_name_to_move_after;
- How to create new horizontal row for each field in django form?
- How to set WSGIPassAuthorization when serving Django via runmodwsgi
Source:stackexchange.com