LoginSignup
55
33

More than 5 years have passed since last update.

herokuでmysql(ClearDB)を使うとidが10ずつ増える

Posted at

herokuでmysqlを使い開発していたところ、ローカルでは出現しなかった謎のエラーに悩まされたので調べてみたところ、データベースのidが1,11,21,31,41,...と10ずつ増えていた。
これでは困るので解決策を探ってみがどうやらこういう仕様らしい。
レプリケーション時にキーが衝突しないようにするためらしい。
次のように設定すると一時的に1ずつ増えるよう設定できるが、railsを通してレコードを追加すると元に戻ってしまう。
SET @@auto_increment_increment = 1;
そもそもキーの衝突を防ぐよう設定されているClearDBの仕様なので、無理やり変更するのはあまりよくない気がする。

以下参考URL

http://stackoverflow.com/questions/14078288/heroku-mysql-auto-increment
http://www.cleardb.com/developers/help/faq#general_16

55
33
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
55
33