技術

【Rails】idのauto increment設定を削除する

投稿日:

こんにちは

railsを触っていてidからauto incrementの設定を削除したい時がありました。
やり方は簡単で、

id: false
t.column :id, 'int(11) PRIMARY KEY'

を追加します。

実際のコードを下記になります。

class CreateGenres < ActiveRecord::Migration[5.2]
  def change
    create_table :genres, id: false do |t|
      t.column :id, 'int(11) PRIMARY KEY'
      t.string :name

      t.timestamps
    end
  end
end

これでidからauto incrementの設定が削除できました。

-技術

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

no image

【nginx/unicorn】(13: Permission denied) while connecting to upstream

どうも中田です。 AWS上でAPIサーバを構築してて、 * Webサーバ:ngi …

no image

【Rails】El Captain で’$rails s’ が動かない件

どうも中田です。 開発用MacをEl Capitanにアップデートしたところ r …

no image

[Angular] router-outletの外で現在のurlを取得

こんにちは、コーテッグのこやまです。 Angularでapp.component …

no image

HTMLタグだけでアコーディオンを実装する

こんにちは htmlタグのdetailsというのは知っていますか? 僕も初めて知 …

[ionic] Error code 70 / requires a provisioning profile with the Push Notifications feature.

どうも中田です ionic使っててbuildで引っかかりましたー ionicでp …