2

I have a table which i created as shown below

op.create_table('test',
                    sa.Column('userid', sa.String(length=60), nullable=False),
                    sa.Column('page_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['userid'], ['map.userid']),
                )

I want add a ondelete="CASCADE" constraint on the foreign key. I understand we need to do drop_contraint and create_foreign_key. But how do i drop_contraint foreign key which has no Name in alembic?

nocturnal
  • 395
  • 2
  • 6
  • 15

1 Answers1

3

If ForeignKey was created without name, then the name will be autogenerated. The format of this name is dependent on the database you’re using.

The name can be found, for instance, like this:

    SELECT * 
    FROM information_schema.key_column_usage 
    WHERE table_name='$table_name';
Valentina
  • 518
  • 7
  • 18