Hello all,
All help and advise is appreciated. I kept on getting the error (Ecto.NoResultsError) expected at least one result but got none in query: .
I tried running the query in the database itself and it works.
SELECT a0.“id”, a0.“airline”, a0.“arrivalcity”, a0.“arrivaldate”, a0.“arrive_time”, a0.“arrivedatetime”, a0.“date”, a0.“depart_time”, a0.“departcity”, a0.“departdate”, a0.“departdatetime”, a0.“flightnumber”, a0.“isconn”, a0.“pnr_id”, a0.“segment_confirmation”, a0.“segmentnumber”, a0.“status”, a0.“tripit_id”, a0.“user_id” FROM “airsegments” AS a0 WHERE a0.“id” = 2000000000
But when I try in my application, I keep on getting the below:
[info] GET /api/airsegments/2000000000
[debug] Processing with ApiWeb.AirSegmentController.show/2
Parameters: %{“id” => “2000000000”}
Pipelines: []
[debug] QUERY OK source=“airsegments” db=3375.0ms queue=47.0ms idle=1703.0ms
SELECT a0.“id”, a0.“airline”, a0.“arrivalcity”, a0.“arrivaldate”, a0.“arrive_time”, a0.“arrivedatetime”, a0.“date”, a0.“depart_time”, a0.“departcity”, a0.“departdate”, a0.“departdatetime”, a0.“flightnumber”, a0.“isconn”, a0.“pnr_id”, a0.“segment_confirmation”, a0.“segmentnumber”, a0.“status”, a0.“tripit_id”, a0.“user_id” FROM “airsegments” AS a0 WHERE (a0.“id” = $1) [2000000000]
[info] Sent 404 in 3546ms
[debug] ** (Ecto.NoResultsError) expected at least one result but got none in query:
from a0 in Api.Itineraries.AirSegment,
where: a0.id == ^“2000000000”
(ecto 3.4.4) lib/ecto/repo/queryable.ex:122: Ecto.Repo.Queryable.one!/3
(api 0.1.0) lib/api_web/controllers/air_segment_controller.ex:24: ApiWeb.AirSegmentController.show/2
(api 0.1.0) lib/api_web/controllers/air_segment_controller.ex:1: ApiWeb.AirSegmentController.action/2
(api 0.1.0) lib/api_web/controllers/air_segment_controller.ex:1: ApiWeb.AirSegmentController.phoenix_controller_pipeline/2
(phoenix 1.4.17) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
(api 0.1.0) lib/api_web/endpoint.ex:1: ApiWeb.Endpoint.plug_builder_call/2
(api 0.1.0) lib/plug/debugger.ex:132: ApiWeb.Endpoint."call (overridable 3)"/2
(api 0.1.0) lib/api_web/endpoint.ex:1: ApiWeb.Endpoint.call/2
(phoenix 1.4.17) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.7.0) c:/projects-api/api-phoenix/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
(cowboy 2.7.0) c:/projects-api/api-phoenix/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3
(cowboy 2.7.0) c:/projects-api/api-phoenix/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3
(stdlib 3.8) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
The only reason I could think of is that the psql db table data type does not match my schema? This is a table that existed before the schema, so I built the schema around it.
Schema:
field :airline, :string
field :arrivalcity, :string
field :arrivaldate, :date
field :arrive_time, :string
field :arrivedatetime, :naive_datetime
field :date, :string
field :depart_time, :string
field :departcity, :string
field :departdate, :date
field :departdatetime, :naive_datetime
field :flightnumber, :string
field :isconn, :boolean, default: false
field :pnr_id, :integer
field :segment_confirmation, :string
field :segmentnumber, :integer
field :status, :string
field :tripit_id, :string
field :user_id, :integer
Table Structure:
“id”,“bigint”
“pnr_id”,“bigint”
“segmentnumber”,“smallint”
“date”,“character varying”
“flightnumber”,“character varying”
“departdate”,“date”
“departcity”,“character varying”
“arrivalcity”,“character varying”
“arrivaldate”,“date”
“user_id”,“bigint”
“airline”,“character varying”
“tripit_id”,“character varying”
“depart_time”,“character varying”
“arrive_time”,“character varying”
“status”,“character varying”
“departdatetime”,“timestamp without time zone”
“arrivedatetime”,“timestamp without time zone”
“isconn”,“boolean”
“segment_confirmation”,“character varying”