Index: django/db/models/fields/__init__.py
===================================================================
--- django/db/models/fields/__init__.py	(revision 6650)
+++ django/db/models/fields/__init__.py	(working copy)
@@ -206,16 +206,21 @@
         return value
 
     def get_db_prep_lookup(self, lookup_type, value):
+        from django.db import connection
         "Returns field's value prepared for database lookup."
         if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'search'):
             return [value]
         elif lookup_type in ('range', 'in'):
             return value
         elif lookup_type in ('contains', 'icontains'):
+            if connection.features.uses_custom_icontains and lookup_type == 'icontains':
+                return [value]    
             return ["%%%s%%" % prep_for_like_query(value)]
         elif lookup_type == 'iexact':
             return [prep_for_like_query(value)]
         elif lookup_type in ('startswith', 'istartswith'):
+            if connection.features.uses_custom_startswith:
+                return [value]
             return ["%s%%" % prep_for_like_query(value)]
         elif lookup_type in ('endswith', 'iendswith'):
             return ["%%%s" % prep_for_like_query(value)]
@@ -478,6 +483,9 @@
         defaults.update(kwargs)
         return super(CharField, self).formfield(**defaults)
 
+class ASCIICharField(CharField):
+    pass
+
 # TODO: Maybe move this into contrib, because it's specialized.
 class CommaSeparatedIntegerField(CharField):
     def get_manipulator_field_objs(self):
@@ -587,7 +595,9 @@
             # doesn't support microseconds.
             if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
                 value = value.replace(microsecond=0)
-            value = smart_unicode(value)
+            #Firebird supports native datetime
+            if settings.DATABASE_ENGINE != 'firebird':
+                value = smart_unicode(value)
         return Field.get_db_prep_save(self, value)
 
     def get_db_prep_lookup(self, lookup_type, value):
@@ -995,8 +1005,8 @@
             # doesn't support microseconds.
             if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
                 value = value.replace(microsecond=0)
-            if settings.DATABASE_ENGINE == 'oracle':
-                # cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
+            if settings.DATABASE_ENGINE in ('oracle', 'firebird'):
+                # cx_Oracle and kinterbasdb expect a datetime.datetime to persist into TIMESTAMP field.
                 if isinstance(value, datetime.time):
                     value = datetime.datetime(1900, 1, 1, value.hour, value.minute,
                                               value.second, value.microsecond)
Index: django/db/backends/__init__.py
===================================================================
--- django/db/backends/__init__.py	(revision 6650)
+++ django/db/backends/__init__.py	(working copy)
@@ -45,10 +45,13 @@
     autoindexes_primary_keys = True
     inline_fk_references = True
     needs_datetime_string_cast = True
+    needs_default_null = False
     needs_upper_for_iops = False
     supports_constraints = True
     supports_tablespaces = False
     uses_case_insensitive_names = False
+    uses_custom_icontains = False
+    uses_custom_startswith = False
     uses_custom_queryset = False
 
 class BaseDatabaseOperations(object):
@@ -65,7 +68,14 @@
         This SQL is executed when a table is created.
         """
         return None
-
+    
+    def cascade_delete_update_sql(self):
+        """
+        Returns the SQL necessary to make a cascading deletes and updates
+        of foreign key references during a CREATE TABLE statement.
+        """
+        return ''
+    
     def date_extract_sql(self, lookup_type, field_name):
         """
         Given a lookup_type of 'year', 'month' or 'day', returns the SQL that
Index: django/core/management/sql.py
===================================================================
--- django/core/management/sql.py	(revision 6650)
+++ django/core/management/sql.py	(working copy)
@@ -263,7 +263,10 @@
         # Make the definition (e.g. 'foo VARCHAR(30)') for this field.
         field_output = [style.SQL_FIELD(qn(f.column)),
             style.SQL_COLTYPE(col_type)]
-        field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or '')))
+        nullstring = ""
+        if connection.features.needs_default_null:
+            nullstring = "DEFAULT "
+        field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or nullstring)))
         if f.unique and (not f.primary_key or connection.features.allows_unique_and_pk):
             field_output.append(style.SQL_KEYWORD('UNIQUE'))
         if f.primary_key:
@@ -276,8 +279,8 @@
             if inline_references and f.rel.to in known_models:
                 field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \
                     style.SQL_TABLE(qn(f.rel.to._meta.db_table)) + ' (' + \
-                    style.SQL_FIELD(qn(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' +
-                    connection.ops.deferrable_sql()
+                    style.SQL_FIELD(qn(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' + \
+                    connection.ops.cascade_delete_update_sql() + connection.ops.deferrable_sql()
                 )
             else:
                 # We haven't yet created the table to which this field
@@ -335,6 +338,7 @@
                 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \
                     (qn(r_table), truncate_name(r_name, connection.ops.max_name_length()),
                     qn(r_col), qn(table), qn(col),
+                    connection.ops.cascade_delete_update_sql(),
                     connection.ops.deferrable_sql()))
             del pending_references[model]
     return final_output
@@ -364,19 +368,21 @@
                 tablespace_sql))
             if inline_references:
                 deferred = []
-                table_output.append('    %s %s %s %s (%s)%s,' %
+                table_output.append('    %s %s %s %s (%s)%s%s,' %
                     (style.SQL_FIELD(qn(f.m2m_column_name())),
                     style.SQL_COLTYPE(models.ForeignKey(model).db_type()),
                     style.SQL_KEYWORD('NOT NULL REFERENCES'),
                     style.SQL_TABLE(qn(opts.db_table)),
                     style.SQL_FIELD(qn(opts.pk.column)),
+                    connection.ops.cascade_delete_update_sql(),
                     connection.ops.deferrable_sql()))
-                table_output.append('    %s %s %s %s (%s)%s,' %
+                table_output.append('    %s %s %s %s (%s)%s%s,' %
                     (style.SQL_FIELD(qn(f.m2m_reverse_name())),
                     style.SQL_COLTYPE(models.ForeignKey(f.rel.to).db_type()),
                     style.SQL_KEYWORD('NOT NULL REFERENCES'),
                     style.SQL_TABLE(qn(f.rel.to._meta.db_table)),
                     style.SQL_FIELD(qn(f.rel.to._meta.pk.column)),
+                    connection.ops.cascade_delete_update_sql(),
                     connection.ops.deferrable_sql()))
             else:
                 table_output.append('    %s %s %s,' %
@@ -412,6 +418,7 @@
                 (qn(r_table),
                 truncate_name(r_name, connection.ops.max_name_length()),
                 qn(r_col), qn(table), qn(col),
+                connection.ops.cascade_delete_update_sql(),
                 connection.ops.deferrable_sql()))
 
             # Add any extra SQL needed to support auto-incrementing PKs
Index: django/contrib/contenttypes/models.py
===================================================================
--- django/contrib/contenttypes/models.py	(revision 6650)
+++ django/contrib/contenttypes/models.py	(working copy)
@@ -1,6 +1,7 @@
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 from django.utils.encoding import smart_unicode
+from django.conf import settings
 
 CONTENT_TYPE_CACHE = {}
 class ContentTypeManager(models.Manager):
@@ -31,10 +32,15 @@
         global CONTENT_TYPE_CACHE
         CONTENT_TYPE_CACHE = {}
 
-class ContentType(models.Model):
+class ContentType(models.Model):   
     name = models.CharField(max_length=100)
-    app_label = models.CharField(max_length=100)
-    model = models.CharField(_('python model class name'), max_length=100)
+    # Need this because of Firebird restrictions on index key size < 252 bytes
+    if settings.DATABASE_ENGINE == 'firebird':
+        app_label = models.ASCIICharField(max_length=96)
+        model = models.ASCIICharField(_('python model class name'), max_length=96)
+    else:
+        app_label = models.CharField(max_length=100)
+        model = models.CharField(_('python model class name'), max_length=100)
     objects = ContentTypeManager()
     class Meta:
         verbose_name = _('content type')
Index: django/contrib/auth/models.py
===================================================================
--- django/contrib/auth/models.py	(revision 6650)
+++ django/contrib/auth/models.py	(working copy)
@@ -6,6 +6,7 @@
 from django.contrib.contenttypes.models import ContentType
 from django.utils.encoding import smart_str
 from django.utils.translation import ugettext_lazy as _
+from django.conf import settings
 import datetime
 import urllib
 
@@ -72,7 +73,11 @@
     """
     name = models.CharField(_('name'), max_length=50)
     content_type = models.ForeignKey(ContentType)
-    codename = models.CharField(_('codename'), max_length=100)
+    # Need this because of Firebird restrictions on index key size < 252 bytes
+    if settings.DATABASE_ENGINE == 'firebird':
+        codename = models.ASCIICharField(_('codename'), max_length=100)
+    else:
+        codename = models.CharField(_('codename'), max_length=100)
 
     class Meta:
         verbose_name = _('permission')
