NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None
Error occurs while performing an app specific makemigration command
NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None
Python script
I am running a simple migration for a model and it eventually creates the migration file 0001_initial.py but I wanted to know what's the meaning of this error and how it can be tackled.
python manage.py makemigrations api
Traceback
Migrations for 'api':
api/migrations/0001_initial.py
- Create model Task
Traceback (most recent call last):
File "manage.py", line 22, in
Error occurs after migrate command too
Python script
python manage.py migrate
Traceback
Operations to perform: Apply all migrations: admin, api, auth, contenttypes, sessions Running migrations: This version of djongo does not support "NULL, NOT NULL column validation check" fully. Visit https://nesdis.github.io/djongo/support/ Applying contenttypes.0001_initial...This version of djongo does not support "schema validation using CONSTRAINT" fully. Visit https://nesdis.github.io/djongo/support/ OK Applying auth.0001_initial...This version of djongo does not support "schema validation using KEY" fully. Visit https://nesdis.github.io/djongo/support/ This version of djongo does not support "schema validation using REFERENCES" fully. Visit https://nesdis.github.io/djongo/support/ OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying api.0001_initial... OK Applying contenttypes.0002_remove_content_type_name...This version of djongo does not support "COLUMN DROP NOT NULL " fully. Visit https://nesdis.github.io/djongo/support/ This version of djongo does not support "DROP CASCADE" fully. Visit https://nesdis.github.io/djongo/support/ Traceback (most recent call last): File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 857, in parse return handler(self, statement) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 894, in _alter query.execute() File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 533, in _drop_column self.db[self.left_table].update( File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/pymongo/collection.py", line 2584, in call raise TypeError("'Collection' object is not callable. If you meant to " TypeError: 'Collection' object is not callable. If you meant to call the 'update' method on a 'Collection' object it is failing because no such method exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/cursor.py", line 51, in execute self.result = Query( File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 784, in init self._query = self.parse() File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 885, in parse raise exe from e djongo.exceptions.SQLDecodeError:
Keyword: None
Sub SQL: None
FAILED SQL: ALTER TABLE "django_content_type" DROP COLUMN "name" CASCADE
Params: ()
Version: 1.3.6
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute raise db_exe from e djongo.database.DatabaseError
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute output = self.handle(*args, **options) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 231, in handle post_migrate_state = executor.migrate( File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 245, in apply_migration state = migration.apply(state, schema_editor) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/migrations/migration.py", line 124, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 178, in database_forwards schema_editor.remove_field(from_model, from_model._meta.get_field(self.name)) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 517, in remove_field self.execute(sql) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 142, in execute cursor.execute(sql, params) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute return super().execute(sql, params) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/utils.py", line 90, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute return self.cursor.execute(sql, params) File "/home/picasso/src/code_practice/python/todo_django_api/env/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute raise db_exe from e django.db.utils.DatabaseError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in
How comes there are still unapplied migrations and I ran the migrate command?
Python Script
python manage.py runserver
Console
You have 12 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.
December 11, 2021 - 10:15:14 Django version 3.0.3, using settings 'todo_django_api.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
Yes, I am also facing the same issues
Using pymongo 3.12.1 will solve your problem,I have faced this problem one hours ago
Thanks @dzyt82
I found a workaround, when using the call_command, I do not see this error:
NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None
I am not sure why it's working, but maybe it could be helpful.
Python script
from django.core.management import call_command
call_command("migrate")
I am using: pymongo==4.0.1 djongo==1.3.6
@cruky Where do you place this script in a project??
@dzyt82 I see that version of Pymongo is very healthy, according to Snyk. I'll use that and see.
@MikeTeddyOmondi Hey , have you resolved this issue? , actually I m stucking too into this and not getting any exact solution.
@AmrapaliKumari I haven't gotten through the issue since the last recommended step...The server keeps printing that log anytime I do a migration. I'm still waiting for it to be addressed.
@MikeTeddyOmondi okk Thanks, Is there any other way to integrate MongoDB with Django bcoz according to Django documentation I have tried but still no luck , not getting any other way to restart the project?
Bump, same error. Is anyone figured out how to solve it?
@aurok11 Hii, m also facing the same error, try to upgrade or downgrade the versions of djongo and django hope this will help you because earlier I m using django latest version downgrading both djongo and django solved my error.
Using pymongo 3.12.1 will solve your problem,I have faced this problem one hours ago
This works for me. Thx.
So devs apparently it has been a while I touched the project but I found out downgrading the pymongo to version 3.12.1 works great as suggested by @dzyt82 and in addition, it has good package health according to Snyk; and also while I do a python manage.py migrate and when I perform any CRUD operations it doesn't bring the errors in the console as stated earlier before in the issue.
After Migration:

Now all the migrations are applied and no errors occur when doing CRUD operations:

Requirements.txt file contents looks like this:

So devs apparently it has been a while I touched the project but I found out downgrading the pymongo to version 3.12.1 works great as suggested by @dzyt82 and in addition, it has good package health according to Snyk; and also while I do a
python manage.py migrateand when I perform any CRUD operations it doesn't bring the errors in the console as stated earlier before in the issue.After Migration:
Now all the migrations are applied and no errors occur when doing CRUD operations:
Requirements.txt file contents looks like this:
hi , the djongo adapter doesn't seem to work with django 4.0, any particular reason why you used django 3.0.3? as that's a lil bit old versioned. won't this cause security risk? if there were vulnerabilities in this other version of django?
Hii , Can anyone suggest me 2 or 3 sample projects using django integration with MongoDB database as i was doing using default sqlite . But want to try with using mongoDB
Hi @Jephpico check this issue issue 594 I addressed it there....
Todo or Blog RESTful API @AmrapaliKumari
@MikeTeddyOmondi any youtube channel or any site for reference ?