Django可以插入数据库,但是psql cli似乎没有显示

时间:2018-11-01 16:05:53

标签: django postgresql debugging orm

我正在为Django网络应用编写测试。在我的setupTestData类方法中,我手动创建了如下所示的用户

cls.user = get_user_model().objects.create_user(cls.username, email=cls.email, password=cls.password, first_name=cls.first_name, last_name=cls.last_name)

上面的调用不会失败。但是该记录似乎在DB中根本不存在。

我如何在真实的测试方法中确认这一点,API失败了,因为用户似乎不存在于数据库中。

但是我越过了这个。通过使用

import pdb

# I use this after the .create_user() line to stop execution
# and use psql cli to inspect the test DB but i can't see the inserted row
pdb.set_trace()

在pdb内,我使用以下命令调试Django ORM是否保存了记录。

(Pdb) display cls.user.pk
display cls.user.pk: 1

表示插入的ID为1。

但是在psql中运行select count(*) from Authorization_users会产生0行。

我需要进一步调试方面的帮助。谢谢

0 个答案:

没有答案