I am trying to rename a column in a table which has the primary key constraint to an another name and add a new column with a new type becoming the primary key.
So currently I have :
TABLE (
`id` VARCHAR(36) PRIMARY_KEY,
) table;
I want to rename id to uuid and add a new id as a integer which would become the primary key :
TABLE (
`id` integer PRIMARY_KEY, AUTO_INCRREMENT,
`uuid` VARCHAR(36)
) table;
Trying to do that with sqlalchemy.migrate :
table = sqlalchemy.Table('table', meta, autoload=True)
event.c.id.alter(name='uuid')
id = sqlalchemy.Column('id', sqlalchemy.Integer(),
primary_key=True)
event_uuid.create(event)
result with this error in postgres since the primary key constraint wasn't removed from the old id :
ERROR: Column.create() accepts index_name, primary_key_name and unique_name to generate constraints
If somebody have an idea how to do that
It was actually not too hard after reading the source code of
sqlalchemy.migrate, you need first to drop the constraints simply by accessing it directly :and when creating just add
primary_key_nameto the create method :which would get you the primary key on the newly created
idcolumn