2017-08-16 100 views
1

我製作了一個讀取xml文件並從中填充數據庫的腳本。當我在本地運行它時,它沒有問題。但是,當我在Heroku上運行它,它會通過,並填充一些數據(剛好6個對象),但隨後引發此錯誤:從腳本填充數據庫時Django Heroku DataError

skripta_vnos.py是我填充劇本我在外殼

Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
    File "/app/skripta_vnos.py", line 97, in <module> 
    dob.save() 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 806, in save 
    force_update=force_update, update_fields=update_fields) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", 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/base.py", 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/base.py", line 961, in _do_insert 
    using=using, raw=raw) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", 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/query.py", 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/compiler.py", line 1099, in execute_sql 
    cursor.execute(sql, params) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 80, in execute 
    return super(CursorDebugWrapper, self).execute(sql, params) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute 
    return self.cursor.execute(sql, params) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", 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/utils.py", line 65, in execute 
    return self.cursor.execute(sql, params) 
DataError: value too long for type character varying(100) 

我的模式看起來運行像這樣:

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): 
     return self.name.encode("utf-8") 

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

您是否在前一段時間更改模型? –

回答

0

像shlomta1說你的字符串大於最大長度。嘗試運行heroku run python manage.py migrate,以便將最大長度應用於您的heroku數據庫

1

你得到這個錯誤是因爲你的一個字符串大於最大長度。 如果它在本地工作,您可能已經改變了最大長度,並且沒有將您的更改遷移到Heroku上。