How to turn off auto_increment in Rails Active Record

后端 未结 7 1740
日久生厌
日久生厌 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:20

    That didn't work for me, but the following did:

    create_table(:table_name, :id => false) do |t|
      t.column :id, 'int(11) PRIMARY KEY'
    end
    

    Only problem is that you lose it in the schema.rb.

提交回复
热议问题