Virtual Map Virtual Map - 2 years ago 130
Python Question

Django Heroku DataError when populating database from script

I have made a script that reads xml file and populates database from it. When I run it locally it works with no problems. But when I run it on heroku it goes through and populates some data (exactly 6 objects), but then throws this error:
is my populating script I run it in shell

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/app/", line 97, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 806, in save
force_update=force_update, update_fields=update_fields)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 836, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 922, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 961, in _do_insert
using=using, raw=raw)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/", line 1063, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/", line 1099, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/", line 80, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/", line 65, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/", line 65, in execute
return self.cursor.execute(sql, params)
DataError: value too long for type character varying(100)

my model looks like this:

class Supply(models.Model):
name = models.CharField(max_length=255)
maticna = models.CharField(max_length=255)
organ = models.CharField(max_length=255, null=True, blank=True)
pos = models.CharField(max_length=255, null=True, blank=True)
city = models.CharField(max_length=255, null=True, blank=True)
postn= models.CharField(max_length=255, null=True, blank=True)
hisna = models.CharField(max_length=255, null=True, blank=True)

email = models.CharField(max_length=255, null=True, blank=True)

def __str__(self):

def get_absolute_url(self):
return reverse('supply-detail', args=[str(])

Answer Source

Like shlomta1 said your string is larger than max length. Try running heroku run python migrate so you apply those max lengths to your heroku database too

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download