【发布时间】:2020-06-20 17:49:31
【问题描述】:
我正在尝试将主键从 :id 重命名为 :account_id。
我有以下Schema 和迁移。当我尝试插入记录时,我在 account_id 列上收到来自 Postgres 的“不能为空”错误。
我是否正确设置了自动生成位?我觉得应该在迁移中。
def change do
create table(:accounts) do
add :account_id, :integer, primary_key: true
add :email, :string
timestamps()
end
end
@primary_key {:account_id, :id, autogenerate: true}
schema "accounts" do
field :email, :string
timestamps()
end
【问题讨论】: