oh right, you can filter them out.  Use include_object:

http://alembic.readthedocs.org/en/latest/api.html#alembic.environment.EnvironmentContext.configure.params.include_object

if type == ‘foreign_key_constraint’: return False



dewey <de...@pathoz.com> wrote:

> Thanks for looking at it.
> 
> Is there a simple way I can tell Alembic to ignore foreign keys altogether 
> and i can manage those manually??
> I really prefer that to hand-coding all of my field names.
> 
> Thanks for any suggestions.
> Dewey
> 
> 
> 
> On Friday, January 2, 2015 3:13:07 PM UTC-6, Michael Bayer wrote:
> dewey <de...@pathoz.com <javascript:>> wrote:
> 
>> Ok, I've confirmed the column rename event is called PRIOR to the Alembic 
>> analysis of the models.
>> 
>> I'm not sure how to interpret all this, but I suspect the output below will 
>> tell us what's going on.
>> 
>> I added this line at the end of your "class 
>> _fk_constraint_sig(_constraint_sig):"  constructor:
> 
> first problem is that the render is wrong.  the name we set is not present in 
> the constraints.
> 
> starting with:
> 
> Table(
>     't1', target_metadata,
>     Column('id', Integer, primary_key=True),
>     Column('foo', String)
> )
> 
> Table(
>     't2', target_metadata,
>     Column('id', Integer, primary_key=True),
>     Column('t1id', Integer, ForeignKey('t1.id <http://t1.id/>'))
> )
> 
> it auto generates:
> 
>     op.create_table('t2',
>     sa.Column(u't2_id', sa.Integer(), nullable=False),
>     sa.Column(u't2_t1id', sa.Integer(), nullable=True),
>     sa.ForeignKeyConstraint(['t1id'], ['t1.id <http://t1.id/>'], ),
>     sa.PrimaryKeyConstraint('id')
>     )
> 
> that’s wrong.   It isn’t putting our .key in the Column objects, so the PK 
> and FK’s point to nothing, because these are rendered as pointing to .key.   
> The bug here is that if we aren’t rendering .key in Column (which I think we 
> shouldn’t, for reasons below), we need to render the constraints as referring 
> to the columns by name, not key, which can be different.  So this is issue 
> https://bitbucket.org/zzzeek/alembic/issue/259/autogen-erroneously-gens-constraints-using
>  
> <https://bitbucket.org/zzzeek/alembic/issue/259/autogen-erroneously-gens-constraints-using>.
> 
> If alembic rendered the .key in the migration file like this:
> 
>     op.create_table('t1',
>     sa.Column(u't1_id', sa.Integer(), key='id', nullable=False),
>     sa.Column(u't1_foo', sa.String(), key='foo', nullable=True),
>     sa.PrimaryKeyConstraint('id')
>     )
> 
>     op.create_table('t2',
>     sa.Column(u't2_id', sa.Integer(), key='id', nullable=False),
>     sa.Column(u't2_t1id', sa.Integer(), key='t1id', nullable=True),
>     sa.ForeignKeyConstraint(['t1id'], ['t1.id <http://t1.id/>'], ),
>     sa.PrimaryKeyConstraint('id')
>     )
> 
> that breaks; because there is no MetaData object shared between t1 and t2 in 
> the above context, Alembic has no way to locate ‘t1.id <http://t1.id/>’ when 
> it is onto ‘t2’, so that raises.  Hence I think it’s best that migration 
> scripts be generated fully on column names without keys.
> 
> So we can do that in our migration:
> 
>     op.create_table('t1',
>     sa.Column(u't1_id', sa.Integer(), nullable=False),
>     sa.Column(u't1_foo', sa.String(), nullable=True),
>     sa.PrimaryKeyConstraint('t1_id')
>     )
>     op.create_table('t2',
>     sa.Column(u't2_id', sa.Integer(), nullable=False),
>     sa.Column(u't2_t1id', sa.Integer(), nullable=True),
>     sa.ForeignKeyConstraint(['t2_t1id'], ['t1.t1_id'], ),
>     sa.PrimaryKeyConstraint('t2_id')
>     )
> 
> somehow, you got past all of this part of it.
> 
> The second issue is that the FK comparison is done using column.key from the 
> reflected table.  But column.key here has the table name added to it which 
> does not match our local metadata.   that is a bug, which is 
> https://bitbucket.org/zzzeek/alembic/issue/260/autogenerate-fk-comparison-and-uniques
>  
> <https://bitbucket.org/zzzeek/alembic/issue/260/autogenerate-fk-comparison-and-uniques>.
> 
> Some attempts to work around the second issue haven’t succeeded.
> 
> 
> So short answer is, your use case here is not supported right now; even if 
> you name the columns up front with the naming convention, assuming you still 
> want the .key on the old name, the second issue here is still going to come 
> up.
> 
> These two issues are next on my list for alembic, particularly the second one 
> as it is an issue in the new FK feature.
> 
> 
> 
> 
>> print 'name: %s; const: %s;  cols: %s' % (self.name <http://self.name/>, 
>> self.const, str(self.source_columns))
>> 
>> And I got this output:
>> name: fk_typ_type_typ_stp_bits_stp_super_type; const: 
>> ForeignKeyConstraint([Column(u'typ_stp_bits', Integer(), 
>> ForeignKey(u'stp_super_type.bit'), table=<typ_type>, key='stp_bits')], None, 
>> name='fk_typ_type_typ_stp_bits_stp_super_type', table=Table('typ_type', 
>> MetaData(bind=None), Column(u'typ_mod_dttm', DateTime(), table=<typ_type>, 
>> key='mod_dttm', nullable=False, 
>> onupdate=ColumnDefault(<sqlalchemy.sql.functions.now at 0x1046e8310; now>), 
>> default=ColumnDefault(<sqlalchemy.sql.functions.now at 0x1046dfb90; now>)), 
>> Column(u'typ_encode', SMALLINT(), table=<typ_type>, key='encode', 
>> nullable=False, default=ColumnDefault(0)), Column(u'typ_id', Integer(), 
>> table=<typ_type>, key='id', primary_key=True, nullable=False), 
>> Column(u'typ_name', String(length=50), table=<typ_type>, key='name', 
>> nullable=False), Column(u'typ_stp_bits', Integer(), 
>> ForeignKey(u'stp_super_type.bit'), table=<typ_type>, key='stp_bits'), 
>> Column(u'typ_order', Integer(), table=<typ_type>, key='order', 
>> nullable=False), schema=None));  cols: ['stp_bits']
>> 
>> name: fk_typ_type_typ_stp_bits_stp_super_type; const: 
>> ForeignKeyConstraint([Column('typ_stp_bits', INTEGER(display_width=11), 
>> ForeignKey(u'stp_super_type.stp_bit'), 
>> ForeignKey(u'stp_super_type.stp_bit'), table=<typ_type>)], None, 
>> name=u'fk_typ_type_typ_stp_bits_stp_super_type', table=Table('typ_type', 
>> MetaData(bind=None), Column('typ_mod_dttm', DATETIME(), table=<typ_type>, 
>> nullable=False), Column('typ_encode', SMALLINT(display_width=6), 
>> table=<typ_type>, nullable=False), Column('typ_id', 
>> INTEGER(display_width=11), table=<typ_type>, primary_key=True, 
>> nullable=False), Column('typ_name', VARCHAR(length=50), table=<typ_type>, 
>> nullable=False), Column('typ_stp_bits', INTEGER(display_width=11), 
>> ForeignKey(u'stp_super_type.stp_bit'), 
>> ForeignKey(u'stp_super_type.stp_bit'), table=<typ_type>), 
>> Column('typ_order', INTEGER(display_width=11), table=<typ_type>, 
>> nullable=False), schema=None));  cols: ['typ_stp_bits']
>> 
>> fkey is named fk_typ_type_typ_stp_bits_stp_super_type
>> 
>> INFO  [alembic.autogenerate.compare] Detected removed foreign key 
>> (typ_stp_bits)(stp_bit) on table typ_type
>> 
>> INFO  [alembic.autogenerate.compare] Detected added foreign key 
>> (stp_bits)(stp_bit) on table typ_type
>> 
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sqlalchemy+...@googlegroups.com <javascript:>.
>> To post to this group, send email to sqlal...@googlegroups.com <javascript:>.
>> Visit this group at http://groups.google.com/group/sqlalchemy 
>> <http://groups.google.com/group/sqlalchemy>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com 
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com 
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at http://groups.google.com/group/sqlalchemy 
> <http://groups.google.com/group/sqlalchemy>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

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

Reply via email to