1

I got a problem with creating references in rails 5.1. While rails 5.1 uses bigint(20) for default id, the older still use integer(11) this causes the problem of creating foreign keys(when the new table(rails 5.1) has an association with the older). Now I want to alter all the old id type to bigint, I already created the migration for it, but I faced with another problem: ```

Mysql2::Error: Cannot change column 'id': used in a foreign key constraint 'fk_rails_8faf9b95af' of table 'bene_fitness_server_development.messages': ALTER TABLE `chat_groups` CHANGE `id` `id` bigint NOT NULL

``` How can I alter column with the foreign key by rails?

Mahesh Madushanka
  • 2,902
  • 2
  • 14
  • 28
DinhNgocHien
  • 707
  • 3
  • 17
  • 34
  • from the DB LEVEL you can disable it. (but not recommended) – Mahesh Madushanka Jun 07 '17 at 07:43
  • thanks @MaheshMadushanka, I found this solution, but I want to do it by rails, then the other ones don't have to care about this in the future. – DinhNgocHien Jun 07 '17 at 07:46
  • 1
    Maybe [this helps you](https://stackoverflow.com/questions/32976997/how-can-i-disable-mysql-unique-constraints-in-a-rspec-test) to achieve it with ruby, at least, I hope it does. – Foo Bar Jun 07 '17 at 08:03

0 Answers0