anthropogenic.pages.dev
20240728
Postgresql では auto_increment が効かない
rails db:reset && rails db:migrate してから Model.create() すると id が入るけど、 既存のデータをリストアすると id が nil になってしまう問題に悩まされている。 これでもダメ。
def change
remove_column :mytables, :id
add_column :mytables, :id, :integer, primary_key: true, null: false, autoincrement: true
end
この例を参考に .maximum(:id).next.to_i したらリストアしてからも id が入るようになったけど こんなんが本当に必要なのか? auto increment は MySQL の方言とかいう人もいるし。もう少し調べてみるか。
https://stackoverflow.com/questions/40545281/autoincrement-postgre-db-id-field-in-rails
2024-07-28 23:49:01 +0900 +0900
anime
3
api
1
aws
3
cognito
1
game
1
howto
2
hugo
1
idea
2
life
6
log
2
maxim
2
mdx
1
rails
7
rubocop
1
ruby
1
rust
1
solution
2
stripe
1
tech
17
ui
1
warp
1