Open
Description
Describe the use case
As far as I can tell, there doesn't seem to be a way to specify field order when adding a new column? Ive got an inherited model where it would be nice if any new fields that I create via an autogenerated revision would be entered into the database before the base classes fields.
I know I could manually add an execute
after adding it to alter the table to insert it after another field but that sounds tedious to enforce and a way to preserve field order would be useful.
Databases / Backends / Drivers targeted
mysql in this example
Example Use
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.sql import func
from sqlalchemy.dialects.mysql import TIMESTAMP
class MyModel(MyBase):
existing_field = ...
new_field = ...
class MyBase(DeclarativeBase):
created = Column(TIMESTAMP(fsp=2), server_default=func.now(), nullable=False)
modified = Column(TIMESTAMP(fsp=2), onupdate=func.now(), nullable=False)
The new_field
will be created at the end of the table
existing_field|created |modified |new_field|
-----------+----------------------+----------------------+------------+
0|2017-02-08 16:38:14.65|2017-02-08 16:38:14.65| |
where I'd like to have a way to insert it before a field
existing_field|new_field|created |modified |
-----------+------------+----------------------+----------------------+
0| |2017-02-08 16:38:14.65|2017-02-08 16:38:14.65|
Have a nice day!