Django模型保存不保存到数据库

时间:2013-09-18 08:29:19

标签: django

class PesPayrollLedger(models.Model):

  person = models.ForeignKey(Person,null=False,blank=False)
  year = models.IntegerField(null=False,blank=False)
  month = models.IntegerField(null=False,blank=False,choices=month_choices)
  cutoff_id = models.IntegerField(null=False,blank=False,choices=cutoff_choices)
  payroll_account = models.ForeignKey(PesPayrollAccounts,null=False,blank=False)
  amount = models.DecimalField(max_digits=11, decimal_places=4,null=False,blank=False)
  compensation_avail_id = models.IntegerField(null=True,blank=True)
  status =  models.IntegerField(default=0)
  source_cutoff = models.IntegerField()

  class Meta:
    db_table = 'pes_payroll_ledger'

  def __unicode__(self):
    return str(self.payroll_account)+' ('+str(self.amount)+')'

我刚刚表演过:

l = PesPayrollLedger(person_id=505, year=2013, month=9, cutoff_id=2, payroll_account_id=2, amount = 22.0000, source_cutoff = 201391, status=0, compensation_avail_id=83)
l.save()

没有错误,数据库中没有保存任何条目。 我错过了什么?

1 个答案:

答案 0 :(得分:1)

我觉得你正在使用的django的版本是< 1.6。如果是这种情况,那么您需要确保数据库连接配置

'autocommit': True 

设置,否则它永远不会提交事务。

Docs表示反对。

相关问题