Modify

Ticket #765 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Oracle: proper altering of columns with NULL/NOT NULL

Reported by: Nikolay Zakharov <nikolay@…> Owned by: andrew
Priority: major Milestone: 1.0
Component: databaseapi Version: unknown
Keywords: oracle alter ORA-01442 ORA-01451 Cc:

Description

I'll start with a real-life example. I have app with model Staff that have field

position = models.CharField(max_length=150, null=True)

One of the migrations in that app is a simple altering of max_length from 100 to 150. Autogenerated code:

db.alter_column(
    'intranet_staff', 'position',
    self.gf('django.db.models.fields.CharField')(max_length=150, null=True))

Current oracle backend generates following SQL:

ALTER TABLE "INTRANET_STAFF" MODIFY "POSITION" NVARCHAR2(150) NULL;

But oracle complains with one of the exceptions ORA-01442 or ORA-01451 that it can't set NULL to column that is already NULL. Current code catches this exception and silently suppresses it, leaving column unaltered. I don't fully understand why one need to suppress database error on altering, but it is evident that in use case shown above this leads to silent ignore of column altering. Proper sql in my case would be

ALTER TABLE "INTRANET_STAFF" MODIFY "POSITION" NVARCHAR2(150);

I've changed handling of exceptions mentioned above and now if one occures, sql executes again but without nullity part.

Corresponding changeset: https://bitbucket.org/freevoid/south/changeset/b8f61044aea9

Attachments

Change History

comment:1 Changed 3 years ago by andrew

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 1.0

Thanks - pulled!

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.