Rails : Create a drop table cascade migration

前端 未结 3 2031
滥情空心
滥情空心 2021-02-18 18:52

How do I force a DROP TABLE CASCADE in a Rails 3.2 migration?

Is there an option to pass to drop_table(\"table_name\")?

3条回答
  •  -上瘾入骨i
    2021-02-18 19:34

    You could always run raw SQL in the migration.

    MYSQL:

    execute "DROP TABLE #{:table_name} CASCADE CONSTRAINTS PURGE"
    

    PostgreSQL:

    execute "DROP TABLE #{:table_name} CASCADE"
    

    You can check the documentation of the built-in method drop_table here.

提交回复
热议问题