【发布时间】:2015-11-18 01:41:35
【问题描述】:
我有一个外模
defmodule App.Profile do
use App.Web, :model
alias App.Repo
schema "profiles" do
belongs_to :user, App.User
field :name, :string
field :last_name, :string
field :second_surname, :string
timestamps
end
但有时我想保存到数据库并将用户设置为零,我需要在用户字段中添加一些标志吗?
我的控制器中有这段代码
changeset = Profile.changeset(%Profile{user_id: nil}, profile_params)
但是当我尝试保存时,我得到了这个错误
:erlang.byte_size({:user_id, "can't be blank"})
在数据库中插入 null 的最佳方法是什么?
我正在使用 postgres,当手动插入我的数据时,我可以在 user_id 字段中插入 null。
【问题讨论】:
标签: elixir phoenix-framework ecto