Search code examples
pythonsqlsql-serverdjangodjango-south

Is it possible to set SQL Server query timeout within Django/South?


I have a Django app that I have just migrated to South for model/DB synchronization. I have created a new migration after making some changes to the model (ie. adding a new foreign key field). Here is a sample of the code within the new migration 0002_auto__add_field_table_new_field.py

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding field 'Table.new_field'
        db.add_column(u'Table', 'new_field',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.other_table'], null=True, blank=True),
                      keep_default=False)


    def backwards(self, orm):
        # Deleting field 'Table.new_field'
        db.delete_column(u'Table', 'new_field')

When I attempt to apply the migration the query always times out after roughly 30 seconds, with the following error message:

sqlserver_ado,dbapi.DatabaseError: (-2147352567, 'Exception occured.', (0, u'Microsoft SQL Server Native Client 10.0', u'Query timeout expired', None, 0, -2147217871), None)

Is it possible to increase the SQL Server query timeout? I have been unable to find any specific documentation on this other than how to increase the value within SSMS, but having done this it has made no difference. Is this perhaps done in Django settings.py?


Solution

  • So it turns out that the problem was being caused by the backend python db module sqlserver_ado. It is this module that was determining the query timeout. I have amended my settings.py to now use the sql_server.pyodbc ENGINE instead. The migration has now been applied successfully by making use of this.