How to turn off auto_increment in Rails Active Record

后端 未结 7 1692
日久生厌
日久生厌 2020-12-10 13:00

Is it possible to create primary key without auto_increment flag in ActiveRecord?

I can\'t do

create table :blah, :id          


        
7条回答
  •  攒了一身酷
    2020-12-10 13:45

    In Rails 5 you can do

    create_table :blah, id: :integer do |t|
    

    If you want to change the name of primary key column pass primary_key parameter:

    create_table :blah, id: :integer, primary_key: :my_awesome_id do |t|
    

    See create_table documentation.

提交回复
热议问题