2

我想知道当数据库(PostgreSQL)已分区时,是否可以从 Django(1.5 版)管理员向数据库添加新记录?

更具体地说,在我的数据库中,我已经(通过使用触发器)将一个名为的表Category分区为两个名为category_01和的分区category_02

完成对表的分区后,我尝试将新记录插入其中,但不断收到以下错误:

'NoneType' object has no attribute '__getitem__'.

有人知道如何解决这个问题吗?我也尝试将自定义save()方法添加到模型中,但无济于事。可能是这里最简单的解决方案吗?

4

1 回答 1

2

After 2 days of research, I was finally able to solve this issue on my own. My solution was to override the save(..) method in my model like so:

def save(self, *args, **kwargs):
   #custom save method
   #pdb.set_trace()
   from django.db import connection
   connection.features.can_return_id_from_insert = False
   print "save"

   super(your model name here, self).save(*args, **kwargs)

Thanks for the Django docs and PostgreSQL docs, https://groups.google.com/forum/?fromgroups=#!topic/django-users/-AT4PLOmWAE and https://code.djangoproject.com/ticket/10467 for helping me solve the issue!

于 2013-04-26T10:46:14.763 回答