Add column after another column

我们两清 提交于 2019-12-12 10:47:10

问题


How can I add a column after another column to a database using Alembic or SQLAlchemy? That would be equivalent to this SQL clause:

ALTER TABLE foo
CHANGE COLUMN bar
bar COLUMN_DEFINITION_HERE
AFTER OTHER_COLUMN;
-- or
ALTER TABLE foo ADD COLUMN baz AFTER bar;

I also tried the suggestion in this mailing list thread, but it didn't help.

While the order doesn't matter when querying, it helps readability for large tables when in the SQL shell.


回答1:


Use ALTER with AFTER to specify where to place the column.

ALTER TABLE foo 
CHANGE COLUMN foo1 foo1 INT(10) UNSIGNED NULL DEFAULT NULL AFTER foo2;


来源:https://stackoverflow.com/questions/30461400/add-column-after-another-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!