这是执行脚本后的完整输出当在python上运行脚本时出现此错误我使用django 1.10 python 2.7
File "/usr/bin/snort-sig-parser.py", line 213, in <module>
main()
File "/usr/bin/snort-sig-parser.py", line 205, in main
sig_parse(sig_line, 0,options.branch,options.revision)
File "/usr/bin/snort-sig-parser.py", line 173, in sig_parse
sig_obj.save()
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 824, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 908, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 947, in _do_insert
using=using, raw=raw)
File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 1043, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1054, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 117, in execute
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.IntegrityError: (1048, "Column 'create_timestamp' cannot be null")
这个脚本不能写在mysql数据库上。
这是模型代码的一部分。
class SignatureUpdateSet(models.Model):
create_timestamp = models.DateTimeField()
branch = models.CharField(max_length=80)
revision = models.IntegerField()
new_signatures = models.ManyToManyField(Signature,related_name='new_signatures')
updated_signatures = models.ManyToManyField(Signature,related_name='updated_signatures')
deleted_signatures = models.ManyToManyField(Signature,related_name='deleted_signatures')
#blogpost_id = models.IntegerField(blank=True, null=True)
blogpost = models.ForeignKey(BlogPost,null=True)
class Meta:
managed = False
db_table = 'content_app_signatureupdateset'
答案 0 :(得分:0)
如果您想自动添加时间戳,请在auto_now=True
字段中添加create_timestamp
,否则,如果您想添加当前时间戳以外的任何内容,可以添加blank=True
并添加任何保存之前,如果你喜欢自定义时间戳。
create_timestamp = DateTimeField(auto_now=True) # To save current datetime
create_timestamp = DateTimeField(blank=True) # To save any custom date time