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

ORA-01451: column to be modified to NULL cannot be modified to NULL #699

Open
matwrob opened this issue Feb 6, 2025 · 1 comment
Open

Comments

@matwrob
Copy link

matwrob commented Feb 6, 2025

Hi Team,
I'm working on a Django project that's supposed to run on Oracle 19c database.
I'm developing locally in containers using Oracle XE latest image.
When trying to apply migrations (no custom models, only Django & django-auditlog):
>> docker compose run --rm app sh -c "python manage.py migrate"

Oracle rejects the following migration: 0015_alter_logentry_changes

`DB is available
Operations to perform:
Apply all migrations: admin, auditlog, auth, contenttypes, knox, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying auditlog.0001_initial... OK
Applying auditlog.0002_auto_support_long_primary_keys... OK
Applying auditlog.0003_logentry_remote_addr... OK
Applying auditlog.0004_logentry_detailed_object_repr... OK
Applying auditlog.0005_logentry_additional_data_verbose_name... OK
Applying auditlog.0006_object_pk_index... OK
Applying auditlog.0007_object_pk_type... OK
Applying auditlog.0008_action_index... OK
Applying auditlog.0009_alter_logentry_additional_data... OK
Applying auditlog.0010_alter_logentry_timestamp... OK
Applying auditlog.0011_logentry_serialized_data... OK
Applying auditlog.0012_add_logentry_action_access... OK
Applying auditlog.0013_alter_logentry_timestamp... OK
Applying auditlog.0014_logentry_cid... OK
Applying auditlog.0015_alter_logentry_changes...Traceback (most recent call last):
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/oracle/base.py", line 557, in execute
return self.cursor.execute(query, self._param_generator(params))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cx_Oracle.DatabaseError: ORA-01451: column to be modified to NULL cannot be modified to NULL

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

Traceback (most recent call last):
File "/app/manage.py", line 24, in
main()
File "/app/manage.py", line 20, in main
execute_from_command_line(sys.argv)
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/init.py", line 442, in execute_from_command_line
utility.execute()
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/init.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle
post_migrate_state = executor.migrate(
^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
File "/opt/venv/lib64/python3.11/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/oracle/schema.py", line 75, in alter_field
super().alter_field(model, old_field, new_field, strict)
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/base/schema.py", line 830, in alter_field
self._alter_field(
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/base/schema.py", line 1055, in _alter_field
self.execute(
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/base/schema.py", line 201, in execute
cursor.execute(sql, params)
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/opt/venv/lib64/python3.11/site-packages/django/db/utils.py", line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib64/python3.11/site-packages/django/db/backends/oracle/base.py", line 557, in execute
return self.cursor.execute(query, self._param_generator(params))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.DatabaseError: ORA-01451: column to be modified to NULL cannot be modified to NULL`

The migration in question is the following:

-- Add field changes_text to logentry

ALTER TABLE "AUDITLOG_LOGENTRY" ADD "CHANGES_TEXT" NCLOB DEFAULT '' NULL;
ALTER TABLE "AUDITLOG_LOGENTRY" MODIFY "CHANGES_TEXT" DEFAULT NULL;

-- Alter field changes on logentry

ALTER TABLE "AUDITLOG_LOGENTRY" MODIFY "CHANGES" NULL;
ALTER TABLE "AUDITLOG_LOGENTRY" ADD CONSTRAINT "AUDITLOG__CHANGES_2C529CA8_C" CHECK ("CHANGES" IS JSON);

And the problematic statement is:
ALTER TABLE "AUDITLOG_LOGENTRY" MODIFY "CHANGES" NULL;

Is this issue known?

I understand that Oracle does not allow modifying an existing column from NOT NULL to NULL.
If the issue is well known, is there a "standard" approach to solve it?

@hramezani
Copy link
Member

django-auditlog is not supporting oracle DB

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

2 participants