Hi everyone,
I am new to Elixir and Phoenix , and I have hit a wall. I have troubles creating, with one Web page, 3 entries in our database. Here’s what’s happenning:
We have three tables:
Events <-> Event_Actions <-> Actions
Events and Actions are linked through a many_to_many association called Event_Action . Events actually have 3 many_to_many associations with Actions , through three different tables with different fields, but for the sake of the example I’ve simplified it to one.
When using the Phoenix Web interface, there is an error upon submitting the form.
The Event and Action entries are correctly created but an exception is raised for the association. For some reason, the Timestamps are not inserted.
If I look into the queries outputs, I can see the INSERT INTO actions or events have the timestamps fields but not the “event_actions”.
The error I get is this: ERROR 23502 (not_null_ciolation) null value in column “inserted_at” violates not-null constraint (table: event_start_actions)
If I run the function from iex or test it, it works, the problem only happens when it is executed from the web display.
Here’s the function we can test, and that works:
def create_action_on_start(event_id, action_id) do
payload = %Event_Start_Action{
event_id: event_id,
action_id: action_id
}
Repo.insert(payload)
end
If you need any other information, tell me and I’ll tell you. Me and my colleague has put this question on the Reddit and Stack-overflow, we just want this question to be seen.