On Jan 16, 2017 1:31 AM, "Chris Withers" <ch...@withers.org> wrote:

On 10/01/2017 16:05, mike bayer wrote:

>
>
> On 01/10/2017 03:33 AM, Chris Withers wrote:
>
>> Okay, so this worked:
>>
>> op.execute(CreateSequence(Sequence("observation_id_seq")))
>> op.add_column('observation', sa.Column(
>>     'id', sa.Integer(), nullable=False,
>>     server_default=sa.text("nextval('observation_id_seq'::regclass)")
>> ))
>> op.drop_constraint('observation_pkey', table_name='observation')
>> op.create_primary_key('observation_pkey', 'observation', ['id'])
>>
>> ...but how come my original attempt didn't?
>>
>
> when you add a NOT NULL column it needs to be able to create a value for
> all the existing rows, so yeah giving it a server default so it can do
> that is the right way to go.  you can look in your column and see 1, 2,
> 3, 4, 5, 6, 7, ... that it got from that.
>

Sure, but if I was creating a table from scratch, all I'd have to do was
add primary_key=True or autoincrement=True and this would be done for me.



Because there's no data in a brand new table, the server default isn't
needed to create the not-null column.



http://stackoverflow.com/a/19262262/216229 implies the same works for
Alembic, but it didn't work at all for me. So I was wondering if that
answer was wrong, or if I was doing something wrong.


cheers,

Chris

-- 
You received this message because you are subscribed to the Google Groups
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to