Nethan
Nethan

Reputation: 261

Django model save does not save to database

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)+')'

I just performed:

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()

with no errors, no entry has been saved in the database. What did I missed?

Upvotes: 1

Views: 105

Answers (1)

sberry
sberry

Reputation: 132138

I have a feeling that the version of django you are using is < 1.6. If that is the case, then you need to make sure that the db connection config has

'autocommit': True 

set, or else it will never commit the transaction.

Docs for refrerence.

Upvotes: 1

Related Questions