保存django对象时出现内存错误

时间:2015-10-10 15:53:12

标签: python django django-models

我在Django模型结构中应用了继承,如下所示:

class SCUser(User):
    phone = models.CharField(max_length=15,blank=True,null=True)
    address = JSONField(blank=True,null=True)
    photo = models.FileField(upload_to=SCUSER_PHOTOS,blank=True,null=True)
    is_registered = models.BooleanField(default=False)
    registration_key = models.TextField(default='',blank=True,null=True)
    unseen_notifications = models.IntegerField(default=0)

class Employee(SCUser):
    status = models.CharField(max_length=1,choices=AvailabilityStatus)

我差不多完成了完整的项目。 问题是当我尝试保存SCUser或Employee对象时,消耗了大约6 GB的内存,之后我得到了内存错误。这是我的错误日志:

  Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ec2-    user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/base.py", line 710, in save
force_update=force_update, update_fields=update_fields)
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/base.py", line 738, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/base.py", line 803, in _save_table
forced_update)
File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/base.py", line 853, in _do_update
return filtered._update(values) > 0
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 580, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1048, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 829, in execute_sql
cursor.execute(sql, params)
  File "/home/ec2-user/virtualenvs/Snapcuffvnv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 88, in execute
logger.debug('(%.3f) %s; args=%s' % (duration, sql, params),
MemoryError

我不想改变我的模型结构,因为我写了很多代码。

0 个答案:

没有答案