0

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: enter image description here

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

Yeager
  • 5
  • 1
  • 5
  • Are you sure it's the date causing the error? Can you show stack trace? – RonanFelipe Jul 11 '19 at 03:39
  • I'm not sure what exactly a stack trace is, but is it the error I'm shown when I'm attempting to import it? – Yeager Jul 11 '19 at 03:42
  • [Stack Trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors), can you show the lines in the error? Also the rest of the fields in your model would help. – RonanFelipe Jul 11 '19 at 03:47
  • Updated my post with the other models fields, and stack trace – Yeager Jul 11 '19 at 03:58
  • The first line of your error shows `None, None, &: Sora no Mukō de Saki Masuyō ni, None, Akatsuki Works, PLAYSTATION3, 2013-12-26 00:00:00, None, None`, looks like the releaseDateJP is going with time too (2013-12-26 00:00:00), maybe this is the problem. I suspect from the `MultiSelectField` as well, I never used it before, so not sure how it works, make sure to check the choices have the correct option for that first line. – RonanFelipe Jul 11 '19 at 04:29
  • Also one more thing to take note, checking the parameters again `None, None, &: Sora no Mukō de Saki Masuyō ni, None, Akatsuki Works, PLAYSTATION3, 2013-12-26 00:00:00, None, None`, the first value is `None`, it should be 2 from the picture you have linked, since the line has a number 2 on it. – RonanFelipe Jul 11 '19 at 04:32

0 Answers0