rails unique index on multiple columns fails (sqlite3)

后端 未结 2 700
星月不相逢
星月不相逢 2021-01-24 08:36

Using rails, I set up a HATBM model with a users table, a groups table and a groups_users for the joins (all with scaffold command). Now I want to add a migration to add a uniqu

相关标签:
2条回答
  • 2021-01-24 08:43

    Seems as if the UNIQUE constraint could not be fullfilled with the current data in the table. Check with GROUP BY and COUNT.

    0 讨论(0)
  • 2021-01-24 08:50

    Your "groups_users" table has duplicate data in it so you'd have to either manually clear out the dupes or just reset your database with rake db:reset.

    Once you've cleared the duplicates, either by removing all the data from the database or finding the dupes, you should be able to run rake db:migrate without error.

    PS, make sure you have a backup of your db before you run the command above because it is destructive.

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