默默地截断django模型字段

时间:2013-09-02 19:31:33

标签: python django django-models

我正在尝试将数据大量导入现有数据库。有时,此另一个数据库中的字符串字段包含的字符串大于我将其导入的字段。我很好,我希望系统只是默默地截断,但是我收到一个警告,然后停止执行。

由于这是一个实时数据库,我通过“manage.py shell”运行我的代码,并且当我调用导入例程时,它会在第一个字符串字段之后停止,它会遇到太长时间。奇怪的是它将它插入到我期望截断的数据库中,但随后退出for循环。

谢谢!

这是错误输出:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/blah/blah/update.py", line 41, in updateCommunities
    community.save()
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 434, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/usr/lib/pymodules/python2.6/django/db/models/base.py", line 527, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 1479, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 783, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/usr/lib/pymodules/python2.6/django/db/models/sql/compiler.py", line 727, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/pymodules/python2.6/django/db/backends/util.py", line 15, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/pymodules/python2.6/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 168, in execute
    if not self._defer_warnings: self._warning_check()
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 82, in _warning_check
    warn(w[-1], self.Warning, 3)
Warning: Data truncated for column 'community_name' at row 1

0 个答案:

没有答案