【发布时间】:2017-06-14 10:45:55
【问题描述】:
我有一个用 django 构建的项目,它使用 postgres 数据库。 该数据库由 CSV 文件填充。所以当我想插入一个新对象时,我得到了错误“重复键”,因为 id = 1 的对象已经存在。
代码:
user = User(name= "Foo")
user.save()
表 users 在 id 上有 PK。
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
如果我在 psql 中得到表的详细信息,我得到:
Column| Type | Modifiers
------+-------- +--------------------------------------
id | integer | not null default nextval('users_id_seq'::regclass)
另外,如果我在创建变量 user 之后保存它之前执行 user.dict,我会得到 'id': None
如何使用未使用的 id 保存用户?
【问题讨论】:
标签: python django postgresql