weixin_39890652 2020-11-30 11:26
浏览 0

add documentation examples for constraint naming practices

Migrated issue, originally created by Carl Meyer ()

I'm adding "ON DELETE CASCADE" to a foreign key constraint that was earlier created as part of a create_table migration, and realizing that this seems to require deleting and recreating the constraint. To delete the existing constraint (without a bunch of ugly and not-offline-compatible inspection code) requires that I previously named it explicitly. But I can't go back in time and change the initial create-table migration to name it explicitly.

Is there a good reason for autogen to not give constraints explicit reliable names by default?

该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

7条回答 默认 最新

  • weixin_39890652 2020-11-30 11:26
    关注

    Carl Meyer () wrote:

    Thanks for that link, I'll look into that approach.

    I understand SQLA's philosophy, but I'm not sure that it should apply to Alembic autogen migrations (which you are heavily encouraged to review anyway). It seems clear that an explicitly-named constraint is the best practice, so I think that rather than allowing new users to shoot themselves in the foot, Alembic should just pick a reasonable default naming convention and document how to use events to set your own preferred naming convention.

    评论

报告相同问题?