LoginSignup
7
2

More than 3 years have passed since last update.

Elixir Ecto で bigint を使う方法(MyXQLアダプタ)

Last updated at Posted at 2020-07-11

背景

references で外部キー設定したくないけど、bigint型にはしたいなーと思ってドキュメント探してみたら :integer しかない・・・!どうすれば!?
※なおMyXQLアダプタを使っています

方法

Ectoのドキュメントでは見つけられませんでしたが :bigint というアトムが使えるみたいですね
https://stackoverflow.com/questions/45400665/ecto-or-elixir-datatype-that-maps-to-mysql-bigint

  def change do
    create table(:characters) do
      add :name, :string
      add :movie_id, :bigint
    end
  end
CREATE TABLE `characters` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `movie_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

おまけ

migration で作られるsqlを出したい場合以下のコマンドで出せるので参考にどうぞ

mysqldump -uroot --compact -d データベース名 | sed -e '/\/\*/d'
7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2