Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从脚本填充数据库时发生Django Heroku数据错误_Python_Django_Postgresql_Sqlite_Heroku - Fatal编程技术网

Python 从脚本填充数据库时发生Django Heroku数据错误

Python 从脚本填充数据库时发生Django Heroku数据错误,python,django,postgresql,sqlite,heroku,Python,Django,Postgresql,Sqlite,Heroku,我制作了一个脚本,可以读取xml文件并从中填充数据库。当我在本地运行它时,它不会出现任何问题。但当我在heroku上运行它时,它会遍历并填充一些数据(正好是6个对象),然后抛出以下错误: skripta_vnos.py是我在shell中运行的填充脚本 Traceback (most recent call last): File "<console>", line 1, in <module> File "/app/skripta_vnos.py", line 9

我制作了一个脚本,可以读取xml文件并从中填充数据库。当我在本地运行它时,它不会出现任何问题。但当我在heroku上运行它时,它会遍历并填充一些数据(正好是6个对象),然后抛出以下错误:

skripta_vnos.py
是我在shell中运行的填充脚本

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)

您收到此错误是因为您的一个字符串大于最大长度。
如果它在本地工作,您可能更改了最大长度,并且没有在Heroku上迁移您的更改。

如shlomta1所说,您的字符串大于最大长度。尝试运行
heroku run python manage.py migrate
那么您也将这些最大长度应用到您的heroku数据库中了

您是否在不久前更改了模型?
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)])