Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR ELIXIR

** (Ecto.ConstraintError) constraint error when attempting to insert struct: * id_fkey (foreign_key_constraint)

# This means that the relationship requires a foreign key match in the corresponding table.
# For instance:

  schema "orders" do
     belongs_to :client, FulfillmentCart.Clients.Client
  end

  schema "client" do
      has_many :orders, FulfillmentCart.Orders.Order
  end

### code somewhere else

  %Order{
	client_id: 1 # The value here has to exist in clients table
  }
  |> Orders.create_order() # context method to create order

# The client_id needs to have a value that is in the clients table.

 
PREVIOUS NEXT
Tagged: #constraint #error #attempting #insert
ADD COMMENT
Topic
Name
2+3 =