4
4
from south .v2 import SchemaMigration
5
5
from django .db import models
6
6
7
- class Migration (SchemaMigration ):
8
-
9
- def forwards (self , orm ):
10
- if not db .dry_run :
11
- print """
12
-
13
- BIG FAT WARNING
14
-
15
- This migration adds a TextField (search_names), with an index.
16
- MySQL does not support indexing TEXT/BLOB columns.
17
-
18
- On MySQL, this migration should fail like:
19
-
20
- FATAL ERROR - The following SQL query failed: CREATE INDEX `cities_light_city_cd532746` ON `cities_light_city` (`search_names`);
21
- The error was: (1170, "BLOB/TEXT column 'search_names' used in key specification without a key length")
7
+ from cities_light .settings import INDEX_SEARCH_NAMES
22
8
23
- Since the search_names column should be created anyway, you can get
24
- past this with:
9
+ if INDEX_SEARCH_NAMES :
10
+ INDEX_SEARCH_NAMES_STRING = 'True'
11
+ else :
12
+ INDEX_SEARCH_NAMES_STRING = 'False'
25
13
26
- ./manage.py migrate cities_light --fake 0003
27
- # continue migrating
28
- ./manage.py migrate cities_light
29
-
30
-
31
- If you can think of any better solution, please report it to
32
- GitHub's project page:
33
-
34
- https://github.com/yourlabs/django-cities-light/issues/
35
-
36
-
37
- If you are on anything else than MySQL, you can ignore this message
38
- and enjoy indexing on search_names.
39
- """
14
+ class Migration (SchemaMigration ):
40
15
16
+ def forwards (self , orm ):
41
17
# Adding field 'City.search_names'
42
- db .add_column ('cities_light_city' , 'search_names' , self .gf ('django.db.models.fields.TextField' )(default = '' , max_length = 4000 , db_index = True , blank = True ), keep_default = False )
18
+ db .add_column ('cities_light_city' , 'search_names' , self .gf ('django.db.models.fields.TextField' )(default = '' , max_length = 4000 , db_index = INDEX_SEARCH_NAMES , blank = True ), keep_default = False )
43
19
44
20
45
21
def backwards (self , orm ):
@@ -58,7 +34,7 @@ def backwards(self, orm):
58
34
'longitude' : ('django.db.models.fields.DecimalField' , [], {'null' : 'True' , 'max_digits' : '8' , 'decimal_places' : '5' , 'blank' : 'True' }),
59
35
'name' : ('django.db.models.fields.CharField' , [], {'max_length' : '200' , 'db_index' : 'True' }),
60
36
'name_ascii' : ('django.db.models.fields.CharField' , [], {'max_length' : '200' , 'db_index' : 'True' }),
61
- 'search_names' : ('django.db.models.fields.TextField' , [], {'default' : "''" , 'max_length' : '4000' , 'db_index' : 'True' , 'blank' : 'True' }),
37
+ 'search_names' : ('django.db.models.fields.TextField' , [], {'default' : "''" , 'max_length' : '4000' , 'db_index' : INDEX_SEARCH_NAMES_STRING , 'blank' : 'True' }),
62
38
'slug' : ('autoslug.fields.AutoSlugField' , [], {'unique_with' : '()' , 'max_length' : '50' , 'populate_from' : 'None' , 'db_index' : 'True' })
63
39
},
64
40
'cities_light.country' : {
0 commit comments