Rails: From UUID to ID

前端 未结 1 675
日久生厌
日久生厌 2021-01-22 15:06

I\'ve created a model Order with UUID as the primary key. Now, I\'d like to change it back to a normal incremental integer.

I\'ve tried to run a migration

相关标签:
1条回答
  • 2021-01-22 15:58

    Does the table have data?

    If no, just drop old id column and add new:

    remove_column :orders, :id
    add_column :orders, :id, :primary_key
    

    If yes, rename id column to id_deprecated

    rename_column :orders, :id, :id_deprecated
    add_column :orders, :id, :primary_key
    

    and add your logic to handle references of old_id in other tables.

    0 讨论(0)
提交回复
热议问题