Trying to add timex and timex.ecto to my phoenix project, getting dependancy errors

ecto
phoenix

#1

So I am trying to add Timex and Timex to my phoenix app, and I am getting some dependancy issues.
This is in a newly created phoenix 1.4 project.

I deleted my mix.lock file thinking that it would somehow resolve itself.
Now I have no mix.lock file :frowning:

I also tried a clean:

mix deps.clean --all

The Timex repo says to use 3.x in the README:

My mix.exs has:

  defp deps do
    [
      {:phoenix, "~> 1.4.0"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 4.0"},
      {:ecto_sql, "~> 3.0"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:redix, ">= 0.0.0"},
      {:extwitter, "~> 0.9.3"},
      {:guardian, "~> 1.0"},
      {:timex, "~> 3.0"},
      {:timex_ecto, "~> 3.0"},    
    ]
  end

The error is:

mix deps.get
Resolving Hex dependencies...

Failed to use "ecto" (versions 3.0.0 and 3.0.1) because
  ecto_sql (version 3.0.1) requires ~> 3.0.2
  phoenix_ecto (version 4.0.0) requires ~> 3.0


Failed to use "ecto" (versions 3.0.0 to 3.0.2) because
  ecto_sql (version 3.0.2) requires ~> 3.0.3
  phoenix_ecto (version 4.0.0) requires ~> 3.0


Failed to use "ecto" (versions 3.0.0 to 3.0.3) because
  ecto_sql (version 3.0.3) requires ~> 3.0.4
  phoenix_ecto (version 4.0.0) requires ~> 3.0


Failed to use "ecto" (versions 3.0.0 to 3.0.4) because
  ecto_sql (version 3.0.0) requires ~> 3.0.0
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.0.0 to 3.0.5) requires ~> 2.0


Failed to use "ecto" (versions 3.0.0 to 3.0.4) because
  ecto_sql (version 3.0.0) requires ~> 3.0.0
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.0) requires ~> 2.1.0-rc3


Failed to use "ecto" (versions 3.0.0 to 3.0.4) because
  ecto_sql (version 3.0.0) requires ~> 3.0.0
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.1) requires ~> 2.1.0


Failed to use "ecto" (versions 3.0.0 to 3.0.4) because
  ecto_sql (version 3.0.0) requires ~> 3.0.0
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.2.1 and 3.3.0) requires ~> 2.2


Failed to use "ecto" (versions 3.0.2 to 3.0.4) because
  ecto_sql (version 3.0.1) requires ~> 3.0.2
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.0.0 to 3.0.5) requires ~> 2.0


Failed to use "ecto" (versions 3.0.2 to 3.0.4) because
  ecto_sql (version 3.0.1) requires ~> 3.0.2
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.0) requires ~> 2.1.0-rc3


Failed to use "ecto" (versions 3.0.2 to 3.0.4) because
  ecto_sql (version 3.0.1) requires ~> 3.0.2
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.1) requires ~> 2.1.0


Failed to use "ecto" (versions 3.0.2 to 3.0.4) because
  ecto_sql (version 3.0.1) requires ~> 3.0.2
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.2.1 and 3.3.0) requires ~> 2.2


Failed to use "ecto" (versions 3.0.3 and 3.0.4) because
  ecto_sql (version 3.0.2) requires ~> 3.0.3
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.0.0 to 3.0.5) requires ~> 2.0


Failed to use "ecto" (versions 3.0.3 and 3.0.4) because
  ecto_sql (version 3.0.2) requires ~> 3.0.3
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.0) requires ~> 2.1.0-rc3


Failed to use "ecto" (versions 3.0.3 and 3.0.4) because
  ecto_sql (version 3.0.2) requires ~> 3.0.3
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.1) requires ~> 2.1.0


Failed to use "ecto" (versions 3.0.3 and 3.0.4) because
  ecto_sql (version 3.0.2) requires ~> 3.0.3
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.2.1 and 3.3.0) requires ~> 2.2


Failed to use "ecto" (version 3.0.4) because
  ecto_sql (version 3.0.3) requires ~> 3.0.4
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.0.0 to 3.0.5) requires ~> 2.0


Failed to use "ecto" (version 3.0.4) because
  ecto_sql (version 3.0.3) requires ~> 3.0.4
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (versions 3.2.1 and 3.3.0) requires ~> 2.2


Failed to use "ecto" (version 3.0.4) because
  ecto_sql (version 3.0.3) requires ~> 3.0.4
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.0) requires ~> 2.1.0-rc3


Failed to use "ecto" (version 3.0.4) because
  ecto_sql (version 3.0.3) requires ~> 3.0.4
  phoenix_ecto (version 4.0.0) requires ~> 3.0
  timex_ecto (version 3.1.1) requires ~> 2.1.0

** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}

#2

So I commented out the timex and timex.ecto from my mix.exs file, and mix deps.get worked fine again and the mix.lock file was generated.

If I add the timex and timex.eco back in my mix file, I get this:

Resolving Hex dependencies...

Failed to use "ecto" (version 3.0.4) because

**ecto_sql (version 3.0.3)** requires ~> 3.0.4

**phoenix_ecto (version 4.0.0)** requires ~> 3.0

**timex_ecto (versions 3.0.0 to 3.0.5)** requires ~> 2.0

**mix.lock** specifies 3.0.4

Failed to use "ecto" (version 3.0.4) because

**ecto_sql (version 3.0.3)** requires ~> 3.0.4

**phoenix_ecto (version 4.0.0)** requires ~> 3.0

**timex_ecto (versions 3.2.1 and 3.3.0)** requires ~> 2.2

**mix.lock** specifies 3.0.4

Failed to use "ecto" (version 3.0.4) because

**ecto_sql (version 3.0.3)** requires ~> 3.0.4

**phoenix_ecto (version 4.0.0)** requires ~> 3.0

**timex_ecto (version 3.1.0)** requires ~> 2.1.0-rc3

**mix.lock** specifies 3.0.4

Failed to use "ecto" (version 3.0.4) because

**ecto_sql (version 3.0.3)** requires ~> 3.0.4

**phoenix_ecto (version 4.0.0)** requires ~> 3.0

**timex_ecto (version 3.1.1)** requires ~> 2.1.0

**mix.lock** specifies 3.0.4

**** (Mix) Hex dependency resolution failed, change the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}**

#3

that also links to How to upgrade an app using timex_ecto to Phoenix 1.4 and Ecto 3.0

that states:

so do you really need timex_ecto? (if it’s a new app I would guess not…)


#4

So now to set datetime values for my ecto models I am using:

NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)

Using Timex.now results in an error:

** (ArgumentError) :naive_datetime expects microseconds to be empty, got: ~N[2018-12-04 16:01:08.450466]


#5

Can you show more code - and perhaps especially explain what problem you are trying to solve?
(think this might be a bit of XY problem…)


#6

Show us your Ecto schema file? The type of the relevant field is probably :utc_datetime while it should be :utc_datetime_usec if you want to capture the microseconds in it.

Check out Ecto.Schema primitive types docs.

Additionally, on my machine the truncation works:

iex(1)> NaiveDateTime.utc_now()
~N[2018-12-04 17:30:44.460000]
iex(2)> NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
~N[2018-12-04 17:30:52]


#7
schema "sprints" do
    #field :board_id, :integer
    field :end_dt, :naive_datetime
    field :name, :string
    field :sprint_type, :integer
    field :start_dt, :naive_datetime

    belongs_to :board, Board

    timestamps()
  end

In my seeds.exs file I used this which works:

now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)

So I am using naive_datetime, which I think is the same type that timestamps() uses.

I want to store UTC time in the db. I’ll convert it in the UI for the end user.


#8

Not sure how to further help. You should probably create a migration that changes the type of the inserted_at and updated_at columns and try again afterwards.


#9
schema "sprints" do
    #field :board_id, :integer
    field :end_dt, :utc_datetime
    field :name, :string
    field :sprint_type, :integer
    field :start_dt, :utc_datetime

    belongs_to :board, Board

    timestamps([{:type, :utc_datetime}])
  end

timestamps docs: https://hexdocs.pm/ecto/Ecto.Schema.html#timestamps/1

depending on your migration you might have usec issue and need to use :utc_datetime_usec (but I’m yet to upgrade to ecto 3 - so can’t remember which it is…)