技術

【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 を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

[Ionic] error: archive not found at path ‘platforms/ios/〇〇.xcarchive’ ** EXPORT FAILED **

こんにちは。たなかです。   Ionicを利用したアプリ開発もラストス …

[XCode] clang: error: linker command failed with exit code 1

どうも中田です 本日はシンプルに。 XCodeでbuild時に発生しました。 エ …

rails_logo

[Rails] Controllerで表示してるページのパスを判定したい

Controllerで表示してるページのパスを判定して、条件分岐したいと思います …

[ Ionic ] A problem occurred evaluating project ‘:app’. > Failed to apply plugin [class ‘com.google.gms.googleservices.GoogleServicesPlugin’] > For input string: “+”

こんにちは。たなかです。 相変わらずモバイルアプリ開発やっています。 先日、Io …

no image

【ionic】Cannot read property ‘startTrackerWithId’ of undefined だとよ

どうも中田です。 GoogleAnalyticsプラグインを導入したのですが、A …