Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOT NULL constraint failed: boards_topic.starter_id #20

Open
keithlowc opened this issue Jul 29, 2018 · 2 comments
Open

NOT NULL constraint failed: boards_topic.starter_id #20

keithlowc opened this issue Jul 29, 2018 · 2 comments

Comments

@keithlowc
Copy link

Getting the following error:

Things that I've tried to resolve it:

1- Reset migrations
2- Grep around the different files to find the "boards_topic" pattern, only found it on the db.sqlite binary. Which is created from the models and in the models.py there is no "boards_topic" - So no sure whats going on here.. Please advise.

(django-env) Keiths-MacBook:myproject keithlow$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..................................E.......

ERROR: test_csrf (boards.tests.tests_views.NewTopicTests)

Traceback (most recent call last):
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: boards_topic.starter_id

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

Traceback (most recent call last):
File "/Users/keithlow/Desktop/django-folder/myproject/myproject/boards/tests/tests_views.py", line 94, in test_csrf
response = self.client.post(url,data)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 525, in post
response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 341, in post
secure=secure, **extra)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 404, in generic
return self.request(**r)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/test/client.py", line 485, in request
raise exc_value
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/keithlow/Desktop/django-folder/myproject/myproject/boards/views.py", line 32, in new_topic
topic.save()
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Users/keithlow/Desktop/django-folder/django-env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: boards_topic.starter_id

@marcio-nunes
Copy link

Same issue. All I had to do was create the user.
Now everything is ok.

    def setUp(self):
        Board.objects.create(name='Django', description='Django board')
        User.objects.create_user(username='marcix', email='[email protected]', password='123')

@shweta3695
Copy link

Implemented your solution and it worked! :) Thank you! @marcio-nunes ..
Can you please explain what is happening and how things are changing after I create the user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants