Example #1
0
 def _alter_field(self, model, old_field, new_field, old_type, new_type,
                  old_db_params, new_db_params, strict=False):
     # ALTER COLUMN TYPE is experimental.
     # https://github.com/cockroachdb/cockroach/issues/49329
     if (self.connection.features.is_cockroachdb_21_1 and old_type != new_type or
             getattr(old_field, 'db_collation', None) != getattr(new_field, 'db_collation', None)):
         self.execute('SET enable_experimental_alter_column_type_general = true')
     # Skip to the base class to avoid trying to add or drop
     # PostgreSQL-specific LIKE indexes.
     BaseDatabaseSchemaEditor._alter_field(
         self, model, old_field, new_field, old_type, new_type, old_db_params,
         new_db_params, strict,
     )
     # Add or remove `DEFAULT unique_rowid()` for AutoField.
     old_suffix = old_field.db_type_suffix(self.connection)
     new_suffix = new_field.db_type_suffix(self.connection)
     if old_suffix != new_suffix:
         if new_suffix:
             self.execute(self.sql_alter_column % {
                 'table': self.quote_name(model._meta.db_table),
                 'changes': 'ALTER COLUMN %(column)s SET %(expression)s' % {
                     'column': self.quote_name(new_field.column),
                     'expression': new_suffix,
                 }
             })
         else:
             self.execute(self.sql_alter_column % {
                 'table': self.quote_name(model._meta.db_table),
                 'changes': 'ALTER COLUMN %(column)s DROP DEFAULT' % {
                     'column': self.quote_name(new_field.column),
                 }
             })
Example #2
0
 def _alter_field(self, model, old_field, new_field, old_type, new_type,
                  old_db_params, new_db_params, strict=False):
     # Skip to the base class to avoid trying to add or drop
     # PostgreSQL-specific LIKE indexes.
     BaseDatabaseSchemaEditor._alter_field(
         self, model, old_field, new_field, old_type, new_type, old_db_params,
         new_db_params, strict,
     )
     # Add or remove `DEFAULT unique_rowid()` for AutoField.
     old_suffix = old_field.db_type_suffix(self.connection)
     new_suffix = new_field.db_type_suffix(self.connection)
     if old_suffix != new_suffix:
         if new_suffix:
             self.execute(self.sql_alter_column % {
                 'table': self.quote_name(model._meta.db_table),
                 'changes': 'ALTER COLUMN %(column)s SET %(expression)s' % {
                     'column': self.quote_name(new_field.column),
                     'expression': new_suffix,
                 }
             })
         else:
             self.execute(self.sql_alter_column % {
                 'table': self.quote_name(model._meta.db_table),
                 'changes': 'ALTER COLUMN %(column)s DROP DEFAULT' % {
                     'column': self.quote_name(new_field.column),
                 }
             })
Example #3
0
 def _alter_field(self, model, old_field, new_field, old_type, new_type,
                  old_db_params, new_db_params, strict=False):
     # Skip to the base class to avoid trying to add or drop
     # PostgreSQL-specific LIKE indexes.
     BaseDatabaseSchemaEditor._alter_field(
         self, model, old_field, new_field, old_type, new_type, old_db_params,
         new_db_params, strict,
     )
    def _alter_field(self, model, old_field, new_field, old_type, new_type,
                     old_db_params, new_db_params, strict=False):

        if old_field.db_index or old_field.unique:
            index_name = self._create_index_name(model._meta.db_table, [old_field.column])
            self.execute(self._delete_index_sql(model, index_name))

        BaseDatabaseSchemaEditor._alter_field(
            self, model, old_field, new_field, old_type, new_type, old_db_params,
            new_db_params, strict,
        )