Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir-无法将Ecto.DateTime保存到Postgres数据库中,保存Ecto.Date在该数据库中有效_Elixir_Phoenix Framework_Ecto - Fatal编程技术网

Elixir-无法将Ecto.DateTime保存到Postgres数据库中,保存Ecto.Date在该数据库中有效

Elixir-无法将Ecto.DateTime保存到Postgres数据库中,保存Ecto.Date在该数据库中有效,elixir,phoenix-framework,ecto,Elixir,Phoenix Framework,Ecto,在Phoenix应用程序中,我想将会话记录保存到Postgres DB中,expires字段为12小时后。Mysession模型将expires字段设置为外部日期时间 型号 schema“sessions”做什么 字段:键,:字符串 字段:expires,exto.DateTime 字段:用户id,:整数 时间戳() 结束如果exto.Date起作用,数据库中字段的类型可能是Date而不是utc\u datetime(PostgreSQL中的时间戳)。将其更改为utc\u datetime可以

在Phoenix应用程序中,我想将会话记录保存到Postgres DB中,
expires
字段为12小时后。Mysession模型将expires字段设置为
外部日期时间

型号

schema“sessions”做什么
字段:键,:字符串
字段:expires,exto.DateTime
字段:用户id,:整数
时间戳()

结束
如果
exto.Date
起作用,数据库中字段的类型可能是
Date
而不是
utc\u datetime
PostgreSQL中的时间戳
)。将其更改为
utc\u datetime
可以修复错误。如果使用迁移来创建表,则可以创建一个新表,该表将更改列的类型,如下所示:

def up do
  alter table(:sessions) do
    modify :expires, :utc_datetime
  end
end

def down do
  alter table(:sessions) do
    modify :expires, :date # old type here
  end
end

数据库(或迁移)中的
expires
列的类型是什么?也许您在迁移中使用了
date
类型而不是
datetime
?我使用了!非常感谢。将
expires
字段更改为键入
timestamp
,现在可以正常工作。