Auto_now_add Django奇怪的错误

时间:2014-06-16 14:51:22

标签: django postgresql

我使用的是Postgresql 9.3.4,Windows 7 64 Bit,Django 1.6.5。

我有一个模型(A MODEL),其中一个字段(B FIELD)使用auto_now_add。当我的应用程序向A MODEL添加记录时,我过去没有遇到任何问题。直到今天(2014年6月16日),我得到了Django完整性错误,因为当我的应用程序向A MODEL添加记录时,空值将被添加到B FIELD。

我认为这是我的应用程序/代码的错误。但是,当我在Windows操作系统上更改日期时,例如2014年6月15日2014年6月15日,我可以在B FIELD上添加记录到模型,没有任何完整性错误。它正常工作,正如我的代码所期望的那样。

这是来自A MODEL的快照

class Reservation (models.Model):
    class Meta:
        app_label = 'ghb_manager'

    RESERVATION_TYPE_CHOICES = (
        ('RSV', 'Reservation'),
        ('WI', 'Walk In'),
    )

    reservation_id = models.CharField(max_length=14, primary_key=True)
    identity_number = models.ForeignKey(Guest, db_column='identity_number')
    total = models.IntegerField()
    ammount_due = models.IntegerField()
    departure = models.DateField()
    arrival = models.DateField()
    reservation_type = models.CharField(max_length=20, choices=RESERVATION_TYPE_CHOICES)
    reservation_date = models.DateField(auto_now_add=True)


    def __unicode__(self):
        return self.reservation_id

这是我的代码的快照,添加了导致完整性错误的记录:

rs = Reservation(reservation_id = reservation_code, identity_number = guest, departure = departureRaw, arrival = arrival, total = total, ammount_due = total, reservation_type = "Walk In")
rs.save()

有没有人遇到过这个问题?如果是这样,请给我一些关于这个bug的指导。到现在为止,我对这个bug感到眼花缭乱。

这是我的追溯错误日志

[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792] Internal Server Error: /ghb_manager/add_walkin
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792] Traceback (most recent call last):
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 112, in get_response
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\transaction.py", line 431, in inner
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return func(*args, **kwargs)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "c:/xampp/htdocs/ghb22\\ghb_manager\\views\\add.py", line 325, in walkin_add
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     rs.save()
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py", line 545, in save
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     force_update=force_update, update_fields=update_fields)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py", line 573, in save_base
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py", line 635, in _save_table
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     forced_update)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py", line 679, in _do_update
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return filtered._update(values) > 0
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\query.py", line 510, in _update
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return query.get_compiler(self.db).execute_sql(None)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py", line 980, in execute_sql
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py", line 786, in execute_sql
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     cursor.execute(sql, params)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\backends\\util.py", line 69, in execute
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return super(CursorDebugWrapper, self).execute(sql, params)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\backends\\util.py", line 53, in execute
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return self.cursor.execute(sql, params)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\utils.py", line 99, in __exit__
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     six.reraise(dj_exc_type, dj_exc_value, traceback)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]   File "C:\\Python27\\lib\\site-packages\\django\\db\\backends\\util.py", line 53, in execute
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792]     return self.cursor.execute(sql, params)
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792] IntegrityError: null value in column "reservation_date" violates not-null constraint
[Mon Jun 16 22:49:19.625868 2014] [:error] [pid 2440:tid 1792] DETAIL:  Failing row contains (WI20140616008, 6472052107880006, 270000, 270000, 2014-06-17, 2014-06-16, Walk In, null).

我今天(2014年6月17日)再次测试了系统,我现在可以正确添加记录,没有任何完整性错误。

0 个答案:

没有答案