enrico
Error on updating a 'time' field to NULL using Ecto with Tds adapter
Hi,
I am trying to set the value of a ‘time’ column to NULL using Ecto from a Phoenix app that interacts with a mssql database.
The problem comes when trying to update the value of a ‘time’ field to null (Inserts a struct is ok, even with null value).
I think it is not related to the original project because with a simple ‘ecto’ project the problem is the same: in the test project changing the database adapter to Postgres the problem disappears.
The test project is simple:
migration:
defmodule Hello.Repo.Migrations.CreateInfo do
use Ecto.Migration
def change do
create table(:infos) do
add :name, :string
add :alias, :string
add :simple_time, :time
timestamps()
end
create(unique_index(:infos, :alias))
end
end
schema:
defmodule Hello.Info do
use Ecto.Schema
import Ecto.Changeset
schema "infos" do
field(:alias, :string)
field(:name, :string)
field(:simple_time, :time)
timestamps()
end
def changeset(info, params \\ %{}) do
info
|> cast(params, [:name, :alias, :simple_time])
|> IO.inspect()
|> validate_required([:name, :alias])
|> unique_constraint(:alias)
end
end
Insertion is ok even with null value.
Update causes the error with this message from test suite:
defmodule Hello.InfoTest do
use Hello.RepoCase
...
test "update time field to nil" do
info = %Info{}
changeset = Info.changeset(info, @valid_attrs)
assert {:ok, info} = Repo.insert(changeset)
info = Repo.get!(Info, info.id)
{:ok, update_info} =
info
|> Info.changeset(%{simple_time: nil})
|> Repo.update()
assert update_info.simple_time == nil
end
...
> mix test
...
10:05:02.965 [debug] QUERY ERROR db=0.0ms queue=2.1ms
UPDATE [infos] SET [simple_time] = @1, [updated_at] = @2 WHERE [id] = @3 [nil, ~N[2021-05-27 08:05:02], 1]
1) test update time field to nil (Hello.InfoTest)
test/hello/info_test.exs:26
** (Tds.Error) Line 1 (Error 257): Implicit conversion from data type varbinary to time is not allowed. Use the CONVERT function to run this query.
code: |> Repo.update()
stacktrace:
(ecto_sql 3.6.1) lib/ecto/adapters/sql.ex:749: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto 3.6.1) lib/ecto/repo/schema.ex:717: Ecto.Repo.Schema.apply/4
(ecto 3.6.1) lib/ecto/repo/schema.ex:426: anonymous fn/15 in Ecto.Repo.Schema.do_update/4
test/hello/info_test.exs:36: (test)
...
any help is appreciated
Thanks in advance!
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217
Let’s say I have a map with required and optional k...
New
Other popular topics
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







