doableware/djongo

Unsupported SQL Operations (DROP COLUMN with CASCADE) Error During Django Migrations

CD-rajveer opened this issue · 0 comments

One line description of the issue

Encountering errors related to unsupported SQL operations (DROP COLUMN with CASCADE) when running Django migrations with djongo.

Python script

from djongo import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager

class UserManager(BaseUserManager):
    def create_user(self, email, password=None, **extra_fields):
        if not email:
            raise ValueError('The Email field must be set')
        email = self.normalize_email(email)
        user = self.model(email=email, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, password=None, **extra_fields):
        extra_fields.setdefault('is_staff', True)
        extra_fields.setdefault('is_superuser', True)
        return self.create_user(email, password, **extra_fields)

class User(AbstractBaseUser):
    email = models.EmailField(unique=True)
    name = models.CharField(max_length=30)
    mobile_number = models.CharField(max_length=15)
    company_name = models.CharField(max_length=100)
    designation = models.CharField(max_length=50)
    password = models.CharField(max_length=128)

    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name', 'mobile_number', 'company_name', 'designation']

    def __str__(self):
        return self.email

Traceback

# Paste the complete stack trace of the error encountered here
# Example:
Operations to perform:
  Apply all migrations: myapp
Running migrations:
  Applying myapp.0001_initial...Traceback (most recent call last):
    File "manage.py", line 22, in <module>
      main()
    File "manage.py", line 18, in main
      execute_from_command_line(sys.argv)
    File "/.../django/core/management/__init__.py", line 401, in execute_from_command_line
      utility.execute()
    File "/.../django/core/management/__init__.py", line 395, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/.../django/core/management/base.py", line 330, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/.../django/core/management/base.py", line 371, in execute
      output = self.handle(*args, **options)
    File "/.../django/core/management/base.py", line 85, in wrapped
      res = handle_func(*args, **kwargs)
    File "/.../django/core/management/commands/migrate.py", line 204, in handle
      fake_initial=fake_initial,
    File "/.../django/db/migrations/executor.py", line 91, in migrate
      self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
    File "/.../django/db/migrations/executor.py", line 121, in _migrate_all_forwards
      state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
    File "/.../django/db/migrations/executor.py", line 198, in apply_migration
      state = migration.apply(state, schema_editor)
    File "/.../django/db/migrations/migration.py", line 127, in apply
      operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
    File "/.../django/db/migrations/operations/fields.py", line 112, in database_forwards
      schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
    File "/.../django/db/backends/base/schema.py", line 561, in remove_field
      self.execute(self._alter_remove_field, model, field, self.dry_run)
    File "/.../django/db/backends/base/schema.py", line 1346, in execute
      cursor.execute(sql, params)
    File "/.../django/db/backends/utils.py", line 98, in execute
      return super().execute(sql, params)
    File "/.../django/db/backends/utils.py", line 66, in execute
      return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
    File "/.../django/db/backends/utils.py", line 75, in _execute_with_wrappers
      return executor(sql, params, many, context)
    File "/.../django/db/backends/utils.py", line 84, in _execute
      return self.cursor.execute(sql, params)
    File "/.../djongo/cursor.py", line 59, in execute
      raise db_exe from e
  django.db.utils.DatabaseError
  djongo.database.DatabaseError: '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.