Ecto or Elixir datatype that maps to MySql BIGINT

天大地大妈咪最大 提交于 2020-03-22 06:55:21

问题


I'm new to Elixir and Phoenix (6 months learning), I have a situation where I want to assign an Ecto model's field (not primary key or table ID) to BIGINT in MySql.

I realize when you create an Ecto model, the ID of that model in MySql table would automatically mapped to BIGINT after migration.

After checking this site, I tried to create an Ecto model's field to :integer or :id in both model and its corresponding migration script but it always gives me INT datatype in MySql.

Anybody knows what datatype in Elixir or Ecto that corresponds to BIGINT in MySql, so when I execute the migration script my table will have that particular column as BIGINT?

Thanks


回答1:


The type in the migration should be the actual database type and in the schema it should be the type you want in Elixir. Since Elixir supports arbitrary precision integers, all integer types in databases are usually mapped to the native :integer type. So what you want is to use the :bigint type in the migration and :integer in the schema.

create table(:foos) do
  add :bar, :bigint
end

<!-- -->

schema "foos" do
  field :bar, :integer
end


来源:https://stackoverflow.com/questions/45400665/ecto-or-elixir-datatype-that-maps-to-mysql-bigint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!