映射到MySql BIGINT的Ecto或Elixir数据类型 [英] Ecto or Elixir datatype that maps to MySql BIGINT
问题描述
我是Elixir和Phoenix的新手(学习6个月),遇到一种情况,我想将一个Ecto模型的字段(不是主键或表ID)分配给MySql中的BIGINT.
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.
我意识到,当您创建一个Ecto模型时,MySql表中该模型的ID将在迁移后自动映射到 BIGINT .
I realize when you create an Ecto model, the ID of that model in MySql table would automatically mapped to BIGINT after migration.
在选中该站点之后,我尝试创建一个Ecto模型的字段以<在模型及其对应的迁移脚本中,strong>:integer 或:id 都可以,但是在MySql中,它始终为我提供 INT 数据类型.
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.
任何人都知道Elixir或Ecto中哪种数据类型对应于MySql中的BIGINT,所以当我执行迁移脚本时,我的表将具有该特定列作为BIGINT?
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?
谢谢
推荐答案
迁移中的类型应该是实际的数据库类型,而在架构中,它应该是您在Elixir中想要的类型.由于Elixir支持任意精度的整数,因此数据库中的所有整数类型通常都映射为本机:integer
类型.因此,您要在迁移中使用:bigint
类型,在架构中使用:integer
.
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
这篇关于映射到MySql BIGINT的Ecto或Elixir数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!