On Apr 12, 2012, at 10:42 AM, limodou wrote: > On Thu, Apr 12, 2012 at 10:37 PM, Michael Bayer > <mike...@zzzcomputing.com> wrote: >> >> On Apr 12, 2012, at 4:07 AM, limodou wrote: >> >>> I'm using alembic today, and I found a problem, if I changed the >>> column, it'll automatically create add and drop statment, just like >>> this: >>> >>> op.add_column('bas_grp_user', sa.Column('username', sa.Integer(), >>> nullable=False)) >>> op.drop_column('bas_grp_user', u'USERNAME') >>> >>> But when I ran the upgrade I got: >>> >>> sqlalchemy.exc.OperationalError: (OperationalError) (1060, "Duplicate >>> column name 'username'") 'ALTER TABLE bas_grp_user ADD COLUMN username >>> INTEGER NOT NULL' () >> >> this is a column name change - per the documentation, Alembic can't detect >> these and you need to manually change it to an alter_column(). In this >> case, there seems to be an odd casing change where the DB is reporting the >> name as USERNAME in all caps (usually this is oracle or firebird, though >> alembic should be normalizing these to lowercase....) - but then the >> database can't distinguish between USERNAME and "username". If this is >> happening for all your columns then there might be some dialect-related >> issue at play. Otherwise, if you just changed the name to "USERNAME" in the >> DB with quotes then this is what you'd get. >> > > I defined the column name as "USERNAMEā at first, then I changed it to > "username", so it is the thing I want to change. I know the doc says > it can't detect the column rename, but I think if alembic can put drop > statement before add statement, it'll ok for this situation. What do > you think?
dropping the column then recreating it with a new name IMHO is just wrong, whether or not it works - it needs to be changed to an alter_column regardless. The two Column objects have totally different names in any case - this is a rare edge case where the "two different names" happen to be the same in case insensitive - so there's quirky behavior on the part of the database at play (what database is this ? I'd love to know how you got this outcome). -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.