On Thu, Apr 12, 2012 at 11:38 PM, Michael Bayer
<mike...@zzzcomputing.com> wrote:
>
> 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).
>

I'm using mysql. I also thought about it, and I think you are right.
But I'm in developing stage, so I can drop the whole table at all, I
just want to do is that I can run the upgrade script completely, but
because the order of add and drop, I can't run the script directly,
and I should modify the script so that it can run successfully. I just
don't want to change them by hand.  Maybe there is no a good solution.

-- 
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou

-- 
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.

Reply via email to