I have set up the django-import-export application in my project and have been trying to import data from an Excel spreadsheet but no luck in getting it to work. I deleted my migration files and data base and generated them again to see if that helped but still the same error.
models.py:
from django.db import models
# Create your models here.
class logTimes(models.Model):
fast_finished = models.BooleanField(default=False)
start_date_time = models.DateTimeField('start fast')
end_date_time = models.DateTimeField('end fast')
0001_initial.py:
# Generated by Django 4.0.4 on 2022-07-13 22:14
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='logTimes',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('fast_finished', models.BooleanField(default=False)),
('start_date_time', models.DateTimeField(verbose_name='start fast')),
('end_date_time', models.DateTimeField(verbose_name='end fast')),
],
),
]
admin.py:
from import_export.admin import ImportExportModelAdmin
from django.contrib import admin
from .models import logTimes
@admin.register(logTimes)
class logTimesAdmin(ImportExportModelAdmin):
pass
Line 1 and 2 from my spreadsheet:
The error message in the admin site when attempting import:
Line number: 1 - NOT NULL constraint failed: startandstoptimes_logtimes.start_date_time
True, 05/08/2018 17:15:00, 06/08/2018 13:30:00, None
Traceback (most recent call last):
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 477, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: startandstoptimes_logtimes.start_date_time
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\rlead\anaconda3\lib\site-packages\import_export\resources.py", line 695, in import_row
self.save_instance(instance, using_transactions, dry_run)
File "C:\Users\rlead\anaconda3\lib\site-packages\import_export\resources.py", line 469, in save_instance
instance.save()
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\base.py", line 806, in save
self.save_base(
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\base.py", line 857, in save_base
updated = self._save_table(
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\base.py", line 1000, in _save_table
results = self._do_insert(
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\base.py", line 1041, in _do_insert
return manager._insert(
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\query.py", line 1434, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\models\sql\compiler.py", line 1621, in execute_sql
cursor.execute(sql, params)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 103, in execute
return super().execute(sql, params)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\rlead\anaconda3\lib\site-packages\django\db\backends\sqlite3\base.py", line 477, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: startandstoptimes_logtimes.start_date_time
I tried adding the Primary key ID column to my spreadsheet starting from 1 but that made no difference. In all my research, every solution I have tried has not been successful. If someone can see where I am going wrong, your advice would be great.
