enrico
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!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex









