将.xlsx文件导入模型,收到DateField的Integer超出范围错误:行号:1-超出范围的整数

时间:2019-07-11 03:26:49

标签: python django django-models

我正在尝试将电子游戏电子表格导入Django数据库。我已经设置了带有日期字段的模型,并且我相信我已经格式化了电子表格,使其与Django期望的格式匹配。

我正在使用Django import-export软件包。我试图在Django settings.py文件中手动设置格式,但这似乎无法解决。

  

models.py


from django.db import models
from multiselectfield import MultiSelectField
from django.urls import reverse


class Game(models.Model):

    boxArt = models.ImageField(default='questionmark.png', upload_to='boxart')
    title = models.CharField(max_length=100)
    genres = MultiSelectField(max_choices=5, choices=GENRES, blank=True)
    developers = MultiSelectField(max_choices=5, choices=DEVELOPERS, blank=True)
    platforms = MultiSelectField(max_choices=5, choices=PLATFORMS, blank=True)

    releaseDateJP = models.DateField(null=True,blank=True)
    releaseDatePAL = models.DateField(null=True,blank=True)
    releaseDateNA = models.DateField(null=True,blank=True)

    def __str__(self):
            return f'{self.title} Game'

    def get_absolute_url(self):
        return reverse('game_detail', kwargs={'pk': self.pk})
  

settings.py

DATE_INPUT_FORMATS = ['%Y-%m-%d']

电子表格的第一行如下所示: enter image description here

我希望我的模型可以填充适当的数据;发布日期。但是我认为是第一个日期字段(releaseDateJP)导致了错误:

Errors:
Line number: 1 - integer out of range
None, None, &: Sora no Mukō de Saki Masuyō ni, None, Akatsuki Works, PLAYSTATION3, 2013-12-26 00:00:00, None, None
Traceback (most recent call last):
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.NumericValueOutOfRange: integer out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\import_export\resources.py", line 522, in import_row
self.save_instance(instance, using_transactions, dry_run)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\import_export\resources.py", line 315, in save_instance
instance.save()
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 718, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 748, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 831, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 869, in _do_insert
using=using, raw=raw)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\query.py", line 1136, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\sql\compiler.py", line 1289, in execute_sql
cursor.execute(sql, params)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\J\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: integer out of range

0 个答案:

没有答案