技術

【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

[Angular] リアクティブフォームの値をtsファイルで設定する。

こんにちは、コーテッグの小山です。 Angularのリアクティブフォームについて …

[rubyXL] Unknown child node for element

どうも中田です Excelのテンプレートファイルを読み込んで、値を差し込みダウン …

[Xcode] SDK Version Issue – This app was built with the iOS 12.0 SDK. Starting March 2019, all iOS apps submitted to the App Store must be built with the iOS 12.1 SDK or later, included in Xcode 10.1 or later.

こんにちは。たなかです。 2019年、ブログ初更新になります。今年もよろしくお願 …

no image

【Docker/Mac】Dockerコマンド

どうも中田です。 今回はDocker。 巷でよく話には出てましたが使ってみるとめ …

Amazon Rekognitionを使うと写真に自動でタグを付けられます。

こんにちは、高石です。 来月20日(5月20日)はエンたまもくもく会#5です。 …