I am attempting to import a spreadsheet of video games into my Django database. I have set up the models with date fields, and I believe I have formatted my spreadsheet so that it matches with what Django is expecting.
I am using the Django import-export package. I have tried to manually set the formatting in the Django settings.py
file, but that doesn't seem to fix it.
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']
Here is what the first line of my spreadsheet looks like:
I expect for my models to be filled with the appropriate data; the release dates. But the first date field (releaseDateJP
), is what I believe to be causing the error:
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