Permalink
Browse files

Spruced up the ApiKey migration to not fail on MySQL.

  • Loading branch information...
1 parent 504a487 commit e41ec9c92cd157f2b911f7f27abc3f71614bfb4a @toastdriven toastdriven committed Nov 7, 2012
Showing with 37 additions and 4 deletions.
  1. +28 −0 docs/compatibility_notes.rst
  2. +1 −0 docs/index.rst
  3. +2 −0 docs/toc.rst
  4. +6 −4 tastypie/migrations/0002_add_apikey_index.py
@@ -0,0 +1,28 @@
+.. _ref-compatibility-notes:
+
+===================
+Compatibility Notes
+===================
+
+
+Tastypie does it's best to be a good third-party app, trying to interoperate
@dgerzo

dgerzo Nov 8, 2012

Contributor

s/it's/its/

+with the widest range of Django environments it can. However, there are times
+where certain things aren't possible. We'll do our best to document them here.
+
+
+``ApiKey`` Database Index
+-------------------------
+
+When the ``ApiKey`` model was added to Tastypie, an index was lacking on the
+``key`` field. This was the case until the v0.9.12 release. The model was
+updated & a migration was added (``0002_add_apikey_index.py``). However, due
+to the way MySQL works & the way Django generates index names, this migration
+would fail miserably on many MySQL installs.
+
+If you are using MySQL, South & the ``ApiKey`` authentication class, you should
+manually add an index for the the ``ApiKey.key`` field. Something to the effect
+of::
+
+ BEGIN; -- LOLMySQL
+ CREATE INDEX tastypie_apikey_key_index ON tastypie_apikey (`key`);
+ COMMIT;
View
@@ -14,6 +14,7 @@ interfaces.
non_orm_data_sources
tools
testing
+ compatibility_notes
resources
bundles
View
@@ -11,6 +11,7 @@ Table Of Contents
non_orm_data_sources
tools
testing
+ compatibility_notes
resources
bundles
@@ -23,6 +24,7 @@ Table Of Contents
throttling
paginator
geodjango
+ content_types
cookbook
debugging
@@ -8,12 +8,14 @@
class Migration(SchemaMigration):
def forwards(self, orm):
- # Adding index on 'ApiKey', fields ['key']
- db.create_index('tastypie_apikey', ['key'])
+ if not db.backend_name in ('mysql', 'sqlite'):
+ # Adding index on 'ApiKey', fields ['key']
+ db.create_index('tastypie_apikey', ['key'])
def backwards(self, orm):
- # Removing index on 'ApiKey', fields ['key']
- db.delete_index('tastypie_apikey', ['key'])
+ if not db.backend_name in ('mysql', 'sqlite'):
+ # Removing index on 'ApiKey', fields ['key']
+ db.delete_index('tastypie_apikey', ['key'])
models = {
'auth.group': {

0 comments on commit e41ec9c

Please sign in to comment.